I have a table view with two rows in one section, i.e.
If I want to animate line 1 into a new section, that is the end result:
How should this be achieved? I already tried:
[self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow: 0 inSection: 0]] withRowAnimation:UITableViewRowAnimationNone]; [self.tableView insertSections:[NSIndexSet indexSetWithIndex: 1] withRowAnimation:UITableViewRowAnimationNone]; [self.tableView endUpdates];
However, at least in iOS 8, the line is animated, but then the new section is not displayed (i.e. white, without the bottom line border) until some time after something causes a redraw and returns.
[self.tableView beginUpdates]; [self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; [self.tableView endUpdates];
What causes an exception:
Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
and
[self.tableView beginUpdates]; [self.tableView insertSections:[NSIndexSet indexSetWithIndex: 1] withRowAnimation:UITableViewRowAnimationNone]; [self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; [self.tableView endUpdates];
What causes an exception:
cannot move a row into a newly inserted section (1)
Should I just not animate at all and reload the whole table?
source share