I have a UITableViewController managing a UITableView object in an iPad app. The table view is tied in with a rather complicated constellation of other objects. I am having a problem when I ask it to reload a row as follows:
//indexPath is an NSIndexPath with indexes 0 and 0. At the moment, this is the only cell in the table view.
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
The problem is that the row does not reload. There is never a callback to cellForRowAtIndexPath.
The crazy thing is that if I call reloadRowsAtIndexPaths twice, the second call does trigger the reload:
//indexPath is an NSIndexPath with indexes 0 and 0. At the moment, this is the only cell in the table view.
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone]; // does not reload
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone]; // does reload
I am wondering if anyone else has ever encountered a bug like this, and if so, what was the cause?
reloadRowsAtIndexPaths:...
only works when wrapped inbetween calls to:Outside of that, behavior is undefined. (and as you've discovered, fairly unreliable).
Edit: quoting relevant part of "Table View Programming Guide for iPhone OS":
I know this topic is kind of old, but I came across the same issue and a simple fix. I had a table view and when I called reloadData and/or reloadRowsAtIndexPaths, the tableview method cellForRowAtIndexPath would not fire.
It turns out I hadn't hooked up my tableview IBOutlet in Interface Builder - once that was hooked up everything fired as expected. It's always the little things...
Also, like others have mentioned, if you only need the one call, wrapping it in begin/endUpdates isn't necessary.