简体   繁体   中英

Put a UIViewController on top of a UINavigationController stack

I have a view controller that gets set from the first index of a uinavigationcontroller:

AViewController *aController = [self.navigationController.viewControllers objectAtIndex:0];

But sometimes it doesn't work quite rigtht. When I do this below, after having an app open for a day it just stops at the navigation controller and doesn't load the AViewCo

you should check the navigationController when you use. Just combine the setViewControllers:animated: and viewControllers objectAtIndex:0 methods. If there is not AViewController in the stack. Just new or assign the old one in it by setViewControllers:animated: .

self.navigationController.viewControllers is just getting what you have currently in the UINavigationController . If you get nothing from it, it means that there are no UIViewController inside this UINavigationController . You probably do the check after getting it.

BTW, go check the documentation always. It might have other methods that help you with your situation. Not quite sure what you want to do.

And the time you access the UIViewController might not be loaded fully. That's why you can not get it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM