开发者

Performance issue alloc vs copy

I have a table view with custom cells. Each cell has images and text and 开发者_开发百科they are listening notifications. Anyone knows if it would be better to have a cell allocated as a template in memory and then copy the base layout from that instead allocating a new instance every time i need to create a cell? I have to test that but I'm lazy :) Thanks.


Before you create your cell you should call dequeueReusableCellWithIdentifier: on your UITableView and check if it's nil. If it is, create your new cell with initWithStyle:reuseIdentifier:. Make sure your reuse identifier is the same for all your cells assuming they all have the same layout. That is the standard way Apple prescribes for dealing with this issue you describe.

Take a look here and here for further details.


UITableViewCell doesn't implement the NSCopying protocol, so you'd have to implement that yourself in a custom subclass. So if you're going to wind up writing your own implementation of -copyWithZone:, the question is how would that code be more efficient than whatever it is you're currently doing?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜