-viewDidLoad
:
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle: @"Cancel" style: UIBarButtonItemStylePlain target: self action: @selector(cancel:)]; self.navigationItem.rightBarButtonItem = cancelButton; [cancelButton release];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @selector(addNewSegment)]; self.navigationItem.rightBarButtonItem = addButton; [addButton release];
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;
self.navigationItem.hidesBackButton = YES;
- (void) navigationController: (UINavigationController *) navigationController willShowViewController: (UIViewController *) viewController animated: (BOOL) animated { if (viewController == _menuController) { [_navigationController setNavigationBarHidden: YES animated: YES]; } } // willShowViewController
- (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
GRChooseRideKindViewController *chooseKind = [[GRChooseRideKindViewController alloc] init]; [self.navigationController pushViewController: chooseKind animated: YES]; [chooseKind release];
class PrettyMainMenuViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.navigationController?.delegate = self } } extension PrettyMainMenuViewController: UINavigationControllerDelegate { func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { if viewController === self { navigationController.setNavigationBarHidden(true, animated: true) } else { navigationController.setNavigationBarHidden(false, animated: true) } } }