Skip to content

Instantly share code, notes, and snippets.

@prendio2
Created March 26, 2014 15:05
Show Gist options
  • Save prendio2/9785467 to your computer and use it in GitHub Desktop.
Save prendio2/9785467 to your computer and use it in GitHub Desktop.
Custom viewWillApear to restore selected row when transition is cancelled
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow];
if (selectedRowIndexPath) {
[self.tableView deselectRowAtIndexPath:selectedRowIndexPath animated:YES];
[[self transitionCoordinator] notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
if ([context isCancelled]) {
[self.tableView selectRowAtIndexPath:selectedRowIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}];
}
}
@mikeabdullah
Copy link

The blog post associated with this gist is http://blog.supertop.co/post/80781694515/viewmightappear in case anyone arrives here directly

@mikeabdullah
Copy link

One tweak you may wish to do, is only kick in this logic if (self.clearsSelectionOnViewWillAppear)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment