3

我在我的应用程序中使用ECSlidingViewController来实现侧抽屉效果。当我的初始视图加载时,可见视图后面有一个带有MKMapView的隐藏视图控制器。需要从地图注释中分离出来,我不得不将我的地图视图控制器嵌入到导航控制器中。现在隐藏视图控制器是导航控制器而不是地图视图,因此我的地图仅在导航控制器出现在屏幕上后才会初始化。因此,在地图视图的CLLocationManager委托有时间响应位置viewDidLoad之前调用了设置区域的我的地图。

我需要同步实例化我的导航控制器和根视图控制器。我只是手动segue,但我猜'rootViewController' 关系segue 有我会绕过的实现细节。

4

1 回答 1

6

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. 
于 2013-09-10T19:47:22.810 回答