UITableView removes and reloads cells

I delete some rows in a UITableView as follows:

[tableView deleteRowsAtIndexPaths:toDelete withRowAnimation:UITableViewRowAnimationAutomatic];

This adds a nice animation to the delete operation.

However, after deleting, I need to update all currently visible lines. Call

[tableView reloadData];

right after the first call, but the nice animation effect has disappeared. What is the best way to do this? that is, revive the delete operation and update all currently visible rows? Thank!

The reason I need to do this is because each cell contains a checkbox. The controller of my view is the checkbox delegate, and each flag has an NSIndexPath associated with it. When the checkmark is switched, the delegate is called, telling him that we crossed for the x index path. Now, if some rows are deleted, the index paths should be updated. So I need to reload everything so that each flag knows where it is.

+5
source share
3 answers

Note: As noted in the comments, it is likely that this answer will not work . If this were not accepted, I would delete it.

100%, , - . reloadData UIView :

// if self.people is a mutable array
[self.people removeObjectAtIndex:13];

[UIView animateWithDuration:0.5 animations:^{
  [self.tableView reloadData];
}];
-1

ctrahey , . UITableView , . Github, .

https://github.com/VansonLeung/VanTableController

unit test. UITableView - :

[tableView_ beginUpdates];
[tableView_ deleteRowsAtIndexPaths: indexPathDelete withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView_ insertRowsAtIndexPaths: indexPathInsert withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView_ reloadRowsAtIndexPaths: indexPathReload withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView_ endUpdates];

, indexPath , ! .

+1

, . , , . UITableViewCell , NSIndexPath. , indexPath, .

, - Apple , reloadData .

Apple docs

, , , , .. , . , . , , . , , , beginUpdates endUpdates

0

All Articles