How to Add a Home Navigation Button to the iPhone NavigationController

138

A quite useful button for a navigation controller with a deep stack would be a home button. It is simple to add.

In your RootViewController viewDidLoad Function

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *homeButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Home", @"")       style:UIBarButtonItemStyleBordered  target:self action:@selector(goHome:)] autorelease];
    self.navigationItem.rightBarButtonItem = homeButton;
}

That will add a home button in to top right of your navigation controller

Create a function called go home in your rootViewController

// return to root view
- (void)goHome:(id) sender {  
   [self.navigationController popToRootViewControllerAnimated:YES];
}

This function will pop your view controller to its root view



0 comments ↓

If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment