Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jagatnibas

macrumors regular
Original poster
Jul 28, 2008
126
0
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 ?

regards
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
It looks like CellIdentifier issue, it does not initialize the cell again once it is created already.
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.