开发者

Setting UITableViewCell height is expensive

I am doing a comparison in

- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)开发者_开发百科indexPath

It seems like performance of my app really slows down when I check if a cell.detailTextLabel.text isEqualTo:@"None";

What is a better way of doing the comparison and setting the cell height?


UITableView has a complex caching structure implemented to reuse cells as needed because it is expensive to recreate the underlying buffers for drawing management. Changing the cell height will require these buffers be reallocated and you'll lose any performance gained from the caching mechanism.

A better implementation would be to divide the cells you do allocate into groups by height, and reuse the cells based on their height requirements. That way no buffers would need to be reallocated and you'll get the performance you expect from the UITableView.


heightForRowAtIndexPath is being used during the creation of a cell, and as such should not access the cell. Instead of checking the contents of the cell, check the same source you would use to set the contents of the cell.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜