hurshagrawal
hurshagrawal

Reputation: 673

UITableViewCell is frozen (not rerendering with new data). How to fix?

Having some issues with a tableViewCell freezing. I have a table view cell with a list of exercises. When I add a new exercise on another viewController, then pop back to this tableViewController that lists all the exercises, the respective cell gets frozen (see screenshot). Then, if I call [self.tableCell reloadData], that cell never refreshes.

it's weird because if the offending cell is, say, index #4, and I change the data source to only have 2 items, the 4th cell is still frozen. (the first 2 render correctly, the 3rd is blank, 4th is offending cell)

List of all exercises:

https://dl.dropbox.com/u/2795448/Screenshots/ot.png

When I change the data in the tableView data source, that cell is still frozen:

https://dl.dropbox.com/u/2795448/Screenshots/ou.png

If I put a breakpoint and inspect the tableView, it doesn't say anything about that frozen cell:

https://dl.dropbox.com/u/2795448/Screenshots/ov.png

Not sure where to go from here :( It seems to only happen when I insert a row from a different viewController then pop back to this one.

Any thoughts? Thanks so much for any help!

Upvotes: 0

Views: 175

Answers (2)

NightFury
NightFury

Reputation: 13546

I exactly don't understand your way of managing tableview along with data source. If you make any change in data source, same changes should be reflected in tableview as well. (Both should be synchronized). You can use:

Table reloadRowsAtIndexPaths: Table deleteRowsAtIndexPaths: Table insertRowsAtIndexPaths:

to make changes to your tableview and its cells. Or you can just call [Table reloadData]

Remember: never try to store references of UITableViewCells as they are dequeued again on screen - your reference will be just a trash. Just alter your cells using above 3 methods and you are good to go. If you want to clear something, just ask for it.

Upvotes: 1

Mundi
Mundi

Reputation: 80273

You are keeping a reference to a cell. That is a bad idea. It contradicts the whole pattern of datasource and recycling of table cells. All kinds of wacky bugs will be the inevitable result.

Instead, you should make sure your datasource methods return the correct number of sections and rows, and the appropriate cells and then reload your table not a cell.

[self.tableView reloadData]; 

So, for example, when the view is returning from adding a new item, make sure the data array you are using is updated and reload.

Upvotes: 1

Related Questions