开发者

Prevent the UITableView from reusing UITableViewCell?

Is it har开发者_运维问答mful to comment out the code that reuses the cell in a UITableView?

//    if (cell == nil) 
//    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    }

Thanks.

EDIT: Based on the reply of @jrturton, I decided not to do that.


It will increase memory use and affect scrolling performance. If you've only got 10 cells, it probably doesn't make any difference. With 1,000, it will be very noticeable.

You will also need to comment out the dequeue call to the tableView.

I have to ask, though - why are you concerned about this? There may be a better solution to your problem.

Based on your comment, you might still want to reuse a cell per row - otherwise when something is scrolled off screen and returned, you would have to recreate it. You can incorporate the indexPath row and section into the cell reuse string to facilitate this:

NSString *cellIdentifier = [NSString stringWithFormat:@"cell%d.%d",indexPath.section,indexPath.row];


Unless you have a very specific/unique reason, you should use the mechanisms for queueing and de-queing cells that are provided in the template method cellForRowAtIndexPath. This will keep your memory footprint as low as possible and keep scrolling smooth.

Note that you have the ability to modify aspects of a cell each time it is presented, so if you'd care to share your motivation in trying to avoid reusing cells, perhaps my advice would be different.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜