0

可能重复:
其视图不在窗口层次结构中

我的代码有问题。

我想去另一个视图控制器,所以这是我的代码:

- (void)reloadMyTB {
       TestViewController *vc = [[TestViewController alloc] init];
       UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:vc];
       [self presentModalViewController:cntrol animated:NO];
       [cntrol release];
}

但它不起作用,我可以在日志中阅读以下行:

Warning: Attempt to present <UINavigationController: 0x133db4b0> on <ArticleViewController: 0x13828330> whose view is not in the window hierarchy!

谢谢!

4

1 回答 1

1

首先检查您是否在应用程序中实现了导航控制器,如果没有则先实现它然后继续如下

并将视图与文件所有者绑定

请重写您的代码如下

   TestViewController *vc = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil]; //or write TestViewController nib Name here
   UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:vc];
   [self presentModalViewController:cntrol animated:NO];
   [cntrol release]; 
于 2012-11-24T15:59:08.887 回答