0

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

2 Answers 2

1

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];
Sign up to request clarification or add additional context in comments.

2 Comments

I´m not using IB only code. what do you think i was doing wrong?
navigationController is a property of the UIViewController object which gives us the UINavigationController object it is part of. On the other hand navigationController2 is an instance variable within your main view controller class that is a reference to the same object.
0

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

3 Comments

I did it in my AppDelegate.m. Do you have any more idea?
Since navigationController2 is not really a selector but a property, try using "." notation (self.navigationController2). If your synthesize is above where this function is being invoked then you won't receive any error otherwise you'll get an error instead of a warning. I'm guessing your function pasted above was also in AppDelegate.m
Yeah, I don't think you have navigationController2 declared as a property of whatever class "self" is. (It could be something as simple as a misspelling, or you could have it declared in a different class and the current class does not inherit from the class where it's declared.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.