0

Possible Duplicate:
whose view is not in the window hierarchy

I have a problem with my code.

I want to go to another view controller, so here is my code:

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

But it does'nt work and I can read the following line in the log:

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

Thanks!

Community
  • 1
  • 1
  • @Abizern We have added the same link. – sunkehappy Nov 24 '12 at 16:07
  • @sunkehappy Except mine was added by the system when I marked the question as a duplicate. It's better to mark / flag duplicates rather than leave a message as then it keeps the site better focussed and also, if the question gets closed it will be automatically linked to it's duplicate. – Abizern Nov 24 '12 at 16:12
  • Yes but I don't want to put my code in the viewDidLoad or viewDidAppear – userFromGluiras Nov 24 '12 at 16:26

1 Answers1

1

First Check have you implemented Navigation controller in your application, if no then implements it first then go ahead as bellow

And Bind View with Files Owner

Please Rewrite your code as bellow

   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]; 
iDhaval
  • 7,824
  • 2
  • 21
  • 30