iOS chained table view row animation part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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