Is it possible to push (from a UIButton) to another view controller and then access a method from within that view controller?
my code below pushes the RootViewController on the stack. There’s a method within the RootViewController that I’d like to run. Can I do it from the following code somehow?
RootViewController *rootViewController = [[RootViewController alloc]
initWithNibName:@"RootViewController"
bundle:nil];
[self.navigationController pushViewController:rootViewController animated:YES];
thanks for any help
Yes, any method that is visible in the RootViewController header can be accessed like you would call any method on any other object. For instance
[rootViewController someMethod].If you call it directly after the pushViewController, the method will run before the view controller actually animates onto the screen on the next iteration of the runloop.
Though it’s probably best that you do whatever it is you are wanting to do in the
viewDidLoad,viewWillAppear:, orviewDidAppear:methods of your RootViewController, unless it’s something you don’t usually want to happen.