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];
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.
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With