Evan
Evan

Reputation: 1082

error with multiple navigationControllers

I´m making an app which has 2 navigation controllers. One has a tableView, and when a tap in the cells, I want to load the other viewController, but I always have this error:

fifthvieController may no respond to -navigationController2

Here's the code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

                                                                  NSString *letraSeleccionada = [lista objectAtIndex:indexPath.row];
    FourthViewController *fourth = [[FourthViewController alloc]initWithNibName:@"FourthViewController" bundle:nil];
    fourth.letraSeleccionada = letraSeleccionada;

    [[self navigationController2] pushViewController:fourth animated:YES]; //here
    [fourth release];
    fourth = nil;   

}

i have changed the code an now it works but I don´t understand why before it doesn´t work. Here the new code:

      PruebaPushAppDelegate *delegate = [[UIApplication sharedApplication]delegate];

[delegate.navigationController2 pushViewController:fourth animated:YES];

//[[self navigationController2] pushViewController:fourth animated:YES];

Upvotes: 0

Views: 274

Answers (2)

Desdenova
Desdenova

Reputation: 5378

Since you have using two navigation controllers, I'm guessing this is a tab bar application with two tabs and one nav control for each? And you used interface builder for this?

If thats the case you don't need to declare your navigation controllers because your view controllers are already inside them as first view controller.

Just try:

[[self navigationController] pushViewController:fourth animated:YES];

Upvotes: 1

Gary
Gary

Reputation: 4198

Have you declared navigationController2 as a property? Looks like it is only a variable. You can only use "self" with it if you're using properties.

@property (nonatomic, retain) UINavigationController navigationController2;// in .h
@synthesize navigationController2; //in .m

Upvotes: 0

Related Questions