Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar with multiple buttons

Tags:

I have a navigation bar with a left and right button, and I need to put another button next to the right button. Does anyone know how I can go about this? Here is some code to help:

- (id)init {     self = [super initWithStyle:UITableViewStyleGrouped];     if (self) {          _pinArray = [[NSArray alloc]init];         _pinArray = [Data singleton].annotations;          UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"Map"                                                                  style:UIBarButtonItemStylePlain                                                             target:self                                                             action:@selector(goToMap:)];         self.navigationItem.rightBarButtonItem = right;          UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithTitle:@"Menu"                                                             style:UIBarButtonItemStylePlain                                                            target:self                                                            action:@selector(goToMenu:)];         self.navigationItem.leftBarButtonItem = left;         self.navigationItem.title = @"My Homes";     }     return self; } 
like image 631
Chandler De Angelis Avatar asked Jan 15 '13 01:01

Chandler De Angelis


People also ask

How do I add more buttons to my navigation bar?

From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen.

How many buttons are there on navigation bar?

You can use the navigation buttons to move through menus. There are four navigational buttons that you can use to move throughout a menu: up, down, right, and left. Each button corresponds to the direction that you can move in a menu.


2 Answers

It's quite easy :)

https://developer.apple.com/documentation/uikit/uinavigationitem/1624956-rightbarbuttonitems

navigationItem.rightBarButtonItems = [rightA, rightB] // @[rightA, rightB] for ObjC 
like image 109
Ryan Poolos Avatar answered Nov 29 '22 10:11

Ryan Poolos


Instead of using self.navigationItem.rightBarButtonItem, use

self.navigationItem.rightBarButtonItems //note the plural 

This allows you to set an array of buttons rather than a single one.

See the UINavigationItem class reference for details.

like image 42
David Ravetti Avatar answered Nov 29 '22 11:11

David Ravetti