How to add custom buttons to a UINavigationBar?


This question already has an answer here:

  • Can't assign multiple Buttons to UINavigationItem when using Storyboard with iOS 5 6 answers

So as my question states, I'm trying to add custom buttons to a UINavigationBar. AFAIK, you can only add a leftbutton and a rightbutton. However, I want to add 2 more, 1 on each side of the title. Is there any way to do this? :)

You can easily add more buttons to both sides by accessing the following:

  1. create programatically the buttons that you want.
  2. get a reference to the navigationitem buttons array
  3. add the buttons to the array like this:

    rightAddButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(doSomething:)]; 
    editButtonItem = ....; 
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:self.editButtonItem,rightAddButton,nil];