IPhone: failed UITableView sequence with insertRowsAtIndexPaths
Hopefully you can help as I'm a little stuck on where to look for the solution to this UITableView problem I have:
UITableView, (. ), , : , , - . , , .. / , - please . , . , .
// Amend the data source before updating the view to reflect the changes
[[self.playerData objectAtIndex: 0] removeObjectAtIndex: row];
[[self.playerData objectAtIndex: 1] insertObject:playerName atIndex:0];
// Amend the view to reflect changes
NSArray *deleteIndexPaths = [NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:row inSection:0],
nil];
NSArray *insertIndexPaths = [NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:0 inSection:1],
nil];
[self.playerTableView beginUpdates];
[self.playerTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation: UITableViewRowAnimationLeft];
[self.playerTableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation: UITableViewRowAnimationLeft];
[self.playerTableView endUpdates];
Of course, if I just sent the message: [self.playerTableView reloadData]; the view will display correctly. However, we really need this routine to be animated to provide a smooth experience. Perhaps if there was a delegated event that got fired after the insert animation finished, I could update the view from the thbe datasource to get rid of the glitches, but I didn't find a hook like this.
Any help would be greatly appreciated.
source to share
Find the answer. This may not be the most efficient, although in our conditions it will be good, since we are dealing with only a few cells. I fixed it by updating other cells that were clearly not being redrawn:
// Fix for cells not rendered correctly after insertion of top cell]
[self.playerTableView reloadRowsAtIndexPaths:reloadIndexPaths withRowAnimation: UITableViewRowAnimationNone];
I was probably expecting too many UITableView: it would sort the corners for me while the insertRowsAtIndexPaths implementation was running.
FYI info this code was placed right after the beginUpdates-endUpdates block. Everything else seems to be the cause of the accident, although it has not been investigated.
Thank.
source to share
Better option is to reload visible lines and then insert new lines.
self.tableView.beginUpdates()
self.tableView.reloadRowsAtIndexPaths(self.tableView.indexPathsForVisibleRows!, withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.endUpdates()
source to share