简体   繁体   English

如何在屏幕外加载导航控制器时加载其根视图控制器?

[英]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.

相关问题 如何知道何时将加载导航控制器的根视图控制器? - How to know when the root view controller of a navigation controller is going to be loaded? 当自定义viewController作为根视图控制器而不是Navigation Controller作为self.window.rootViewController添加时,视图不会加载 - View is not loaded when custom viewController added as a root view controller instead of Navigation Controller as the self.window.rootViewController iOS 7中导航控制器及其根视图控制器的奇怪行为 - Weird behavior with navigation controller and its root view controller in iOS 7 更改根视图控制器时,如何释放以前的视图控制器? - How can I release the previous view controller when I change the root view controller? 按下视图控制器时如何隐藏导航栏? - How can I hide the navigation bar when pushing a view controller? 如果我们将swrevealview用作初始视图控制器,如何将swrevealview设置为第三视图控制器 - how can i place swrevealview as a third view controller,if we make swrevealview as a initial view controller its working 我只能使UINavigationController在第二级加载,而不能在Root View Controller加载 - I can make UINavigationController load only at 2nd level, not at Root View Controller iOS:当我在导航堆栈中向下两级时,如何访问根视图控制器中使用的变量? - iOS: How to get access to a variable used in the root view controller when I'm 2 levels down in the navigation stack? 如何以编程方式将下一个视图控制器推入导航控制器? - How can I push the next view controller on a navigation controller programmatically? 如何将根视图更改为导航控制器? - How to change Root View to Navigation Controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM