Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add another button next to the "back" button on the left of a UINavigationBar

I've tried this for hours but I still cannot solve it. When using UINavigationController and push a new view controller on top, I got a free "back" button on the left of the navigation bar. I want another button just next to it (to show a popover menu). I wonder what is the correct way to do that. Or I have to hide the free back button and make the same one by myself? If that's the case, I also need to pop the current view controller when pressing my own back button, right?

Thanks for your help.

like image 990
322896 Avatar asked Jul 03 '11 06:07

322896


People also ask

How do I change the navigation bar on my Iphone?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.

What is a navigation controller?

NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.


1 Answers

As stated by steipete in the comment to the question, this is possible starting from iOS 5. You can use

self.navigationItem.leftItemsSupplementBackButton = YES;

and then you just need to add an UIBarButtonItem as leftButton to get a second button after the back button

UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStylePlain target:self action:@selector(yourAction)];
self.navigationItem.leftBarButtonItem = secondButton;
like image 133
Fmessina Avatar answered Oct 06 '22 23:10

Fmessina