How to get notified when a tableViewController fin

2019-09-06 14:59发布

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?

2条回答
贪生不怕死
2楼-- · 2019-09-06 15:11

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];
}    
查看更多
迷人小祖宗
3楼-- · 2019-09-06 15:13

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

查看更多
登录 后发表回答