Mateus Mateus - 21 days ago 10
iOS Question

How to push NavigationController on Xcode 4.2?

With Xcode 4.1, I used to push a Navigation Controller using the following code:

-(IBAction)goClasse1:(id)sender{

Classe1Chamada *goCL1 = [[Classe1Chamada alloc] initWithNibName:@"Classe1Chamada" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:goCL1 animated:YES];
[goCL1];

}


But now I updated to Xcode 4.2, this code just doesn't work. Why? How can I fix it?

Answer

I always use it like this:

-(IBAction)goClasse1:(id)sender{

        Classe1Chamada *goCL1 = [[Classe1Chamada alloc] initWithNibName:@"Classe1Chamada" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:goCL1 animated:YES];
    [goCL1 release];

}

and you don't need to initialize or delegate navigation controller in all your view controllers: it is already initialized in ViewController class.

Comments