views:

494

answers:

1

I'm using the template for a "Utility Application".

In the "FlipSideViewController", I added an IBOutlet for a UINavigationController, navController. In the code, I added the navController just fine. The rootViewController loads perfectly:

navController.viewControllers = [[NSArray arrayWithObject:rootViewController] retain];
[self.view addSubview:navController.view];

I changed the color of the navController just fine:

navController.navigationBar.tintColor = [UIColor colorWithRed:0.6 green:0.75 blue:0.6 alpha:1.0];
navController.navigationBar.translucent = NO;

I make a button (note: "done" refers to a IBAction that dismisses the modalviewcontroller):

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"TEST" style:UIBarButtonItemStyleDone target:self action:@selector(done:)];

I make a navItem using that button:

UINavigationItem *backNavItem = [[UINavigationItem alloc] initWithTitle:@"TESTTEST"];
[backNavItem setRightBarButtonItem:backButton animated:YES];

I try to add that button:

[navController.navigationBar pushNavigationItem:backNavItem animated:YES];

This above code fails miserably. I apparently can't add buttons to the navController because:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.'

Do I have to make a separate UINavigationBar that's somehow connected to my navController? I tried going that route but with no avail.

A: 

I checked out "NavBar" here:

Excellent insight on how to do add buttons. You have to add buttons from the correct ViewController being displayed.

yujean