Skip to content

Instantly share code, notes, and snippets.

@anka
Created January 4, 2015 16:40
Show Gist options
  • Save anka/fbb54113f09385bed2c6 to your computer and use it in GitHub Desktop.
Save anka/fbb54113f09385bed2c6 to your computer and use it in GitHub Desktop.
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