Question

I am having an issue with how the iPhone reuses Cells in table. The problem is that implemented methods of the class also get "reused" and changes in one cell get applied to other cells that were reused. I have a progress indicator that should only be updating in one cell after user interaction, but the progress indicator updates and the method runs inside the 6th cell down too. It happens on the 2nd and 7th cell, also.

I know it's bad for memory to not reuse any cells, but in this app there are never more than 7 or so cells anyway.

 CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

doesn't work. If I scroll away for a second and come back, the Cell is back to normal, and all updates that have happened are reset. The cell destroyed itself and was drawn again, I guess.

I need to know if there's a quick, painless way to make the iPhone just draw every single cell individually without reusing any. Is there a way to maybe use fast iteration or a for loop to create an individual cell for each line in the dataSource?

Please let me reiterate, I'm not ever going to have any more than 7 or 8 cells in one table on a given viewController.

Was it helpful?

Solution 3

What finally worked for me was programatically doing the layout. Using interface builder for TableViewCells is just buggy. Creating a TableViewCell class and the layoutSubviews method with lots of CGRects and frame properties is what got it to work. Even though the cells get reused, the actual data INSIDE THE CELL doesn't overwrite.

OTHER TIPS

If you really want to do it… setup an Array in viewDidLoad that is 7 or 8 long. Do a [[UITableView alloc] initWithStyle:UITabeViewCellStyle… reuseIdentifier:@"whatever"] 7 or 8 times, then in cellForRowAtIndexPath, return the cell from the array. You should make sure to release the array of cells in the dealloc method.

If you only use 7 rows - reuseIdentifyer is useless. How does it work? Imagine that you are scrolling some table with many rows down. There is a moment, when one of the rows shold be hidden and another one will be shown. Only then the table gets cell by reusecellidentifyer. It doesn't allocate memory for another cell. It takes you hidden row and use it for the new row to display. Sorry for my english)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top