Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2015 16:40
What would you like to do?
iOS chained table view row animation part 2
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
// Start a new core animation transaction
[CATransaction begin];
// Set a completion block for the animation
[CATransaction setCompletionBlock:^{
// Update the data model to add a new section
[_data addObject:[NSMutableArray arrayWithObjects:@"Black", nil]];
// Animate the new section apperance
[tableView beginUpdates];
[tableView insertSections:[NSIndexSet indexSetWithIndex:indexPath.section + 1] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
// Update the data model and remove the the selected row
[(NSMutableArray*)_data[indexPath.section] removeObjectAtIndex:indexPath.row];
// Animate the removal of the selected row
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableView endUpdates];
[CATransaction commit];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment