UINavigationController initWithRootVC:如何强制加载VC?

时间:2012-12-10 03:37:55

标签: objective-c ios uiviewcontroller uinavigationcontroller

我创建了一个视图控制器,然后创建了一个导航控制器:

initWithRootViewController:

然后我发现它调用pushViewController:animated:,因为我使用自己的UINavigationController子类,我覆盖pushViewController:animated:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [super pushViewController:viewController animated:animated];
    // do something with the VC
}

问题出在

之后
[super pushViewController:viewController animated:animated];

viewController.isViewLoaded是NO,所以我实际上无法做我想要的,当它被用作导航控制器的根VC时,有没有办法强制加载VC?

谢谢!

编辑,下面是代码:

MyViewController *vc = [[MyViewController alloc] initWithNib:@"" bundle:nil];
MyNavController *nav = [[MyNavController alloc] initWithRootViewController:vc];

self.revealViewController.frontViewController = nav;

2 个答案:

答案 0 :(得分:1)

我在Apple文档中找到了这个答案

  

UINavigationController类实现了一个专门的视图   管理分层内容导航的控制器。这个   class不用于子类化。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

答案 1 :(得分:1)

Access view before pushing viewController.

[viewController view];//this will load your view
[super pushViewController:viewController animated:animated];