Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - difference between topViewController and other forms

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

like image 473
Duck Avatar asked Dec 17 '22 12:12

Duck


1 Answers

topViewController of a navigation controller represents the view controller at the top of the stack. Index 0 is the bottom. topViewController is the object at index 0 only 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 the topViewController doesn't know how to respond to messages intended for a RootViewController instance.

like image 88
Deepak Danduprolu Avatar answered Feb 15 '23 10:02

Deepak Danduprolu