Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force UITableView to call cellForRowAtIndexPath: for all cells

I am having some trouble with UITableView's reloadData method. I have found that it only calls cellForRowAtIndexPath if there are new cells being added or taken away.

Example: I have five cells, each containing five strings. If I add a new cell and call reloadData, the table is updated and I see it. Yet if I go into one of the five cells, add a new string, then return and call reloadData, none of the table view's delegate methods is called.

My question: Is it possible to force the table view to completely reload the data in all of its visible cells?

like image 958
eric.mitchell Avatar asked Jan 21 '12 18:01

eric.mitchell


3 Answers

I found the problem- I had my cell customization code in the if(cell == nil) block, so because the cells were being recycled, they weren't being changed. Taking my customization code out of that block fixed the problem.

like image 163
eric.mitchell Avatar answered Oct 28 '22 18:10

eric.mitchell


I've found that reloading sections reloads data more readily. If you just have one section you can try:

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];

like image 35
jclv Avatar answered Oct 28 '22 17:10

jclv


You can try this

[tableView reloadData];

or

[tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];

put this in commitEditingStyle method.

like image 42
Gangani Roshan Avatar answered Oct 28 '22 18:10

Gangani Roshan