I am on a delegate of a NavigationControl based app.
when I try to access the rootViewController using
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
to run a method, it crashes, saying the method is “unknown” on the rootViewController.
When I access the rootViewController using this
RootViewController *rootViewController = (RootViewController *)[navigationController.viewControllers objectAtIndex:0];
it works.
Which object is the first line accessing?
thanks
topViewControllerof a navigation controller represents the view controller at the top of the stack. Index0is the bottom.topViewControlleris the object at index0only when one view controller is on the stack. If you have more than one, it is not the same. I am guessing that it is the case as it’s crashing because thetopViewControllerdoesn’t know how to respond to messages intended for aRootViewControllerinstance.