Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Buttons on Navigation Bar iOS 5?

I know there is a lot on this topic but I can't get any code to work. Im running iOS5 and building for the iPad and I just can't get two buttons on one side of my navigation bar.

Any help would be appreciated, thanks.

EDIT:

Some code I have tested, its in viewDidLoad, doesn't do anything though.

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save)];

    UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc] initWithTitle:@"Delete" style:UIBarButtonItemStylePlain target:self action:@selector(delete)];

    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:saveButton,deleteButton,nil];
like image 319
Josh Kahane Avatar asked Jul 05 '12 20:07

Josh Kahane


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 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.


1 Answers

In iOS 5 the UINavigationItem gained the array properties: rightBarButtonItems and leftBarButtonItems. You can see more details about how they work in relation to leftBarButtonItem and rightBarButtonItem and the back button here in the class reference.

In short, you just make an array out of your buttons, and set the navigation item's properties as such. I have used this feature to have two buttons on both the left and right of my navigation bar.

EDIT

Here's the code I used to create my arrays. My buttons were all created in interface builder:

self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:backButton, settingsButton, nil];
self.navigationItem.leftItemsSupplementBackButton = YES;

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:continueButton, saveButton, nil];
like image 91
Dan F Avatar answered Oct 01 '22 17:10

Dan F