How to get notified when a tableViewController fin

2019-09-06 14:42发布

问题:

I'm pushing a UITableViewController onto a UINavigationController with pushViewController:animated:. I'd like to be notified the moment the animation finishes so I can use selectRowAtIndexPath to scroll to and highlight a given row.
How can I set the delegate of an animation I didn't call explicitly?

回答1:

I know of no way to set the delegate of the push animation. Here's a simple workaround:

Subclass UITableViewController. Override viewDidAppear: to call your "post-animation" method after a short delay.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self performSelector:@selector(scrollToAndHighlightCurrentRow) withObject:nil afterDelay:0.4];
}    


回答2:

Have you tried simply calling the selectRowAtIndexPath:animated:scrollPosition: method (via the tableView property) before you push it onto the navigation controller's stack?