Possible Duplicate:
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!


谢谢!

最佳答案

首先检查您是否在应用程序中实现了导航控制器,如果没有,则先实现它,然后按以下步骤进行

并与文件所有者绑定视图

请把你的代码改成下面的样子

   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];

10-07 19:56