简体   繁体   中英

How can I make a navigation controller load its root view controller when it is loaded offscreen?

I use ECSlidingViewController for a side-drawer effect in my application. When my initial view loads, there is a hidden view controller with an MKMapView behind the visible view. Needing to segue from map annotations, I had to embed my map view controller in a navigation controller. Now that the hidden view controller is a navigation controller and not a map view so my map initializes only after the navigation controller comes on screen. So my map's viewDidLoad , which sets the region, is called before the map view's CLLocationManager delegate has time to respond with a location.

I need to have my nav controller and root view controller be instantiated synchronously. I would just manually segue, but I would guess the 'rootViewController' relationship segue has implementation details that I would be bypassing.

This was actually pretty simple, and has nothing to do with segues.

I was expecting a rootViewController property on UINavigationController objects while overlooking the @property UIViewController* topViewController .

So in my top (visible) navigation controller's viewWillAppear :

// Load the map's navigation controller from storyboard
MyMapNavigationController* mapNavigation = [self.storyboard instantiateViewControllerWithIdentifier:mapNavigtionIdentifier];

// ECSlidingViewController API to set hidden view controllers
self.slidingViewController.underRightViewController = mapNavigation;

// Grab root view controller
MyMapController* map = mapNavigation.topViewController;

// Slightly hacky magic
[map view]; //lazily instantiated property will initialize view and controller when called. 

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