- Add a cancel button to a navigation bar.
[permalink]
In your -viewDidLoad :
UIBarButtonItem *cancelButton =
[[UIBarButtonItem alloc] initWithTitle: @"Cancel"
style: UIBarButtonItemStylePlain
target: self
action: @selector(cancel:)];
self.navigationItem.rightBarButtonItem = cancelButton;
[cancelButton release]; - Adding a plus button to a navigation bar
[permalink]
UIBarButtonItem *addButton =
[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemAdd
target: self
action: @selector(addNewSegment)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
- Adding an info button to the nav bar
[permalink]
UIButton *button = [UIButton buttonWithType: UIButtonTypeInfoLight];
[button addTarget: self
action: @selector(about:)
forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *infoItem =
[[UIBarButtonItem alloc] initWithCustomView: button];
... make any other button items you want
NSArray *rightButtonItems = @[ spacer, infoItem, widerSpace, someOtherItem ];
_viewController.navigationItem.rightBarButtonItems = rightButtonItems;
- Hide the navigation bar's "Back" button.
[permalink]
self.navigationItem.hidesBackButton = YES;
- Hiding the navigation bar
[permalink]
Say you had a main screen that doesn't need to show the navigation bar. When you "Back" from another view controller your delegate will get called. You can decide then whether to turn off the nav bar.
- (void) navigationController: (UINavigationController *) navigationController
willShowViewController: (UIViewController *) viewController
animated: (BOOL) animated {
if (viewController == _menuController) {
[_navigationController setNavigationBarHidden: YES
animated: YES];
}
} // willShowViewController
- Popping the current view controller
[permalink]
Say the user selected a row in a tableview, and now we're done with this view controller:
- (void)tableView: (UITableView *) tableView
didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
// might want someone to know what the user picked.
[_delegate kindChooser: self
choseWorkoutType: mapRowToWorkoutType(indexPath.row)];
// pop ourselves off the stack.
[self.navigationController popViewControllerAnimated: YES];
} // didSelectRowAtIndexPath
- Pushing a new view controller onto the stack.
[permalink]
Moving to another view controller from the current one.
GRChooseRideKindViewController *chooseKind =
[[GRChooseRideKindViewController alloc] init];
[self.navigationController pushViewController: chooseKind
animated: YES];
[chooseKind release];