Search code examples
objective-cuitableviewios7ios8

UITableView reloadData when editing and keep animations


I'm reloading a UITableView like this by overriding -setEditing:animated in my UITableViewController subclass when the user puts the table view into edit mode.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self.tableView reloadData];
}

This works but is there a way to keep the animations? Normally the red delete button and move button indicators slide into view.

I'm hiding section titles for empty sections but I want to show them when editing so the user can move a table view cell into an empty section which is why I'm doing a table reload when editing.


Solution

  • Try -reloadSections:withRowAnimation: instead.

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing:editing animated:animated];
        // specify appropriate sections you have.
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationAutomatic];
    }