Adding BarButtons to a UINavigationBar after presenting a modal view controller.
Posted
by yujean
on Stack Overflow
See other posts from Stack Overflow
or by yujean
Published on 2010-04-02T21:37:02Z
Indexed on
2010/04/02
21:43 UTC
Read the original article
Hit count: 465
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.
© Stack Overflow or respective owner