[英]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. 我在我的应用程序中使用ECSlidingViewController进行侧抽屉效果。 When my initial view loads, there is a hidden view controller with an MKMapView behind the visible view. 当我的初始视图加载时,有一个隐藏的视图控制器,在可见视图后面有一个MKMapView 。 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. 因此,在地图视图的CLLocationManager委托有时间响应位置之前,将调用我的地图的viewDidLoad
来设置区域。
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. 我只是手动segue,但我猜'rootViewController'关系segue有我将绕过的实现细节。
This was actually pretty simple, and has nothing to do with segues. 这实际上非常简单,与segues无关。
I was expecting a rootViewController
property on UINavigationController
objects while overlooking the @property UIViewController* topViewController
. 我期待UINavigationController
对象上的rootViewController
属性,同时忽略@property UIViewController* topViewController
。
So in my top (visible) navigation controller's viewWillAppear
: 所以在我的顶级(可见)导航控制器的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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.