customcell problem

Discussion in 'iOS Programming' started by jagatnibas, Jul 22, 2009.

  1. jagatnibas macrumors regular

    Jul 28, 2008
    I am using this code in cellForRowAtIndexPath

    the problem is i change self.allItems and do a reloadData to the table view. The number of cells change but the cell appearance does not change. In fact it duplicates last 2 cells. It looks like CellIdentifier issue, it does not initialize the cell again once it is created already. How to solve this type of problems ?

    moreover, where should i release this cell.

    NSString *CellIdentifier = [NSString stringWithFormat:mad:"Cell%d", indexPath.row];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [CustomCell initWithFrame:CGRectZero withIdentifier:CellIdentifier withRecord:[self.allItems objectAtIndex:indexPath.row]];

    return cell;

    is it ok to do

    if(cell != nil)
    [cell release];
    cell = [customCell alloc] initwithframe ....

    everytime allocatiing the cell ?

  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Correct. That is the whole purpose behind cell reuse. This is done for performance reasons, since only so many cells can be shown on the screen at once. It is better to resuse a handful of cells rather than to be deallocating and then reallocating each individual cell. Have you read through the Table View Programming Guide for iPhone OS?

    P.S. Don't worry about releasing cells. That is all handled for you.

Share This Page