I know there is a lot on this topic but I can’t get any code to work. I’m running iOS5 and building for the iPad and I just can’t get two buttons on one side of my navigation bar.
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];
In iOS 5 the
UINavigationItemgained the array properties:rightBarButtonItemsandleftBarButtonItems. You can see more details about how they work in relation toleftBarButtonItemandrightBarButtonItemand 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: