Multiple custom UITableViewCells - ReuseIdentifier and NOT reusing cells

I am having an issue with the iPhone reusing cells in a table. The problem is that implemented class methods are also "reused" and changes in one cell are applied to other cells that have been reused. I have a progress bar that only needs to update in one cell after user interaction, but the progress indicator is updated and the method also runs inside the 6th cell. This also happens on the 2nd and 7th cells.

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

 CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

      

does not work. If I scroll away for a second and come back, the cell is back to normal and any updates that have happened are reset. I think the cage destroyed itself and was drawn again.

I need to know if there is a quick, painless way to make the iPhone just draw each individual cell separately, without reusing. Is there a way to use fast iteration or a for loop to create a separate cell for each row in the data source?

Please let me repeat, I will never have more than 7 or 8 cells in one table on a given viewController.

+2


source to share


3 answers


What finally worked for me was doing the layout programmatically. Using an interface builder for TableViewCells is just cumbersome. Creating a TableViewCell class and layoutSubviews method with lots of CGRects and frame properties is what made it work. Although cells are reused, the actual INSIDE THE CELL data is not overwritten.



0


source


If you really want to do this ... set up the array in viewDidLoad to be 7 or 8. Do [[UITableView alloc] initWithStyle:UITabeViewCellStyle… reuseIdentifier:@"whatever"]

7 or 8 times, then in cellForRowAtIndexPath

, return a cell from the array. You must make sure to free the cell array in the method dealloc

.



+2


source


If you only use 7 lines - reuseIdentifyer is useless. How it works? Imagine you are scrolling down a table with many rows. There is a moment when one of the lines will be hidden and the other will be shown. Only then does the table receive the reusecellidentifyer cell. It does not allocate memory for another cell. It displays the hidden line and uses it to display the new line. Sorry for my English)

0


source







All Articles