Monday, February 7, 2011
Time to debug whether Interface Builder's XIB makes things slow!
When UITableView contains 46410 rows, it took 10+ seconds to see the first application screen. When I added a few NSLog calls, it got worse. Not sure how much, since I gave up after 30 minutes. Finns can be pretty stubborn, even when debugging :)
To make a long story short, the reason was custom cell height implemented as UITableViewDelegate method tableView:heightForRowAtIndexPath. When you create a table, it seems like this method is called for each and every cell in the whole table. In my case it was called 46410 times, I guess. Didn't count them all. The reason for all these calls is that someone needs to know the exact height of the full table, for scrolling purposes. After the initial calculation is done, table was reasonably fast again. XIB didn't seem to make any difference.
How to fix it? Since all my custom cells had always same height, I just set UITableView property rowHeight to common fixed value and removed tableView:heightForRowAtIndexPath. You should define that method only, when your cells have variable heights (done that, too).