05 March 2013

cellForRowAtIndexPath best implementation

After working with cellForRowAtIndexPath in more than a project, it appears that the best implementation (performance-wise) is the following:


CellIdentifier = [NSString stringWithFormat:@"cell%@", @"some_term_per_page"];
cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
                
SomeData* data = [self data:indexPath.row];
        
if ([[cell.contentView subviews] count] > 0)
      [[[cell.contentView subviews]objectAtIndex:0]removeFromSuperview];
        
[cell.contentView addSubview:[DrawingHelper cellView:data]];

No comments: