ViewController问题

时间:2012-11-24 15:46:32

标签: iphone ios viewcontroller

  

可能重复:
  whose view is not in the window hierarchy

我的代码存在问题。

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

- (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!

谢谢!

1 个答案:

答案 0 :(得分: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];