![](/img/trans.png)
[英]How to know when the root view controller of a navigation controller is going to be loaded?
[英]How can I make a navigation controller load its root view controller when it is loaded offscreen?
我在我的應用程序中使用ECSlidingViewController進行側抽屜效果。 當我的初始視圖加載時,有一個隱藏的視圖控制器,在可見視圖后面有一個MKMapView 。 需要從地圖注釋中刪除,我不得不將我的地圖視圖控制器嵌入到導航控制器中。 既然隱藏的視圖控制器是導航控制器而不是地圖視圖,所以我的地圖只有在導航控制器出現在屏幕上后才會初始化。 因此,在地圖視圖的CLLocationManager委托有時間響應位置之前,將調用我的地圖的viewDidLoad
來設置區域。
我需要同步實例化我的導航控制器和根視圖控制器。 我只是手動segue,但我猜'rootViewController'關系segue有我將繞過的實現細節。
這實際上非常簡單,與segues無關。
我期待UINavigationController
對象上的rootViewController
屬性,同時忽略@property UIViewController* topViewController
。
所以在我的頂級(可見)導航控制器的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.