navigationController的问题

时间:2011-09-21 09:01:38

标签: ios uiviewcontroller uikit

[抱歉我的英语不好]

我有一些方法可以创建并显示一些新的视图控制器(在我的基础之上) 当前视图控制器级别)

- (void) switchToDifficultyMenu
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

 DifficultyMenuController *difficultyMenuController = [[DifficultyMenuController alloc] init];

   NSLog(@"navigation controller %@" , self.navigationController); //navContr is nil

 [self.navigationController pushViewController: difficultyMenuController animated: NO];

 [difficultyMenuController release];
[pool release];  


}

当我从我当前的点击事件中触发它时它起作用 查看控制器,但当我尝试在我当前的视图控制器时立即调用它 在它的-viewdidLoad中导航(它是一些需要的)id est导航控制器是 零

我怎样才能让它发挥作用,tnx

1 个答案:

答案 0 :(得分:3)

在您不将UIViewController推送到UINavigationController之前,navigationController属性将为空。在推送之前始终调用viewDidLoad方法。因此,在viewDidLoad中,无法访问此属性。