0

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?

Andrew
  • 8,363
  • 8
  • 43
  • 71

2 Answers2

1

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

John Parker
  • 54,048
  • 11
  • 129
  • 129
  • Yes. That's what I do know, but then the scroll animation finishes at the same time or before the push animation. I want the user to know they're being scrolled to a certain row, by only starting the scroll (and highlight) animation once the push animation has finished. – Andrew Dec 04 '10 at 17:32
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];
}    
James Huddleston
  • 8,410
  • 5
  • 34
  • 39
  • Oh great. So `viewDidAppear` is only called once that push animation is completed? Perfect, That did it. Thanks. – Andrew Dec 04 '10 at 17:36
  • 1
    The `viewDidAppear:` method is also called when a hidden view has its obstructions removed. For example, if you push another view on top of your table view, when you pop that view, the `viewDidAppear:` method of your table view controller will be called again. – James Huddleston Dec 04 '10 at 17:45
  • Please see http://stackoverflow.com/questions/4356256/how-to-get-notified-when-scrolltorowatindexpath-finishes-animating for a follow-up question. – Andrew Dec 04 '10 at 22:50