Slee
Slee

Reputation: 28268

add multiple UIBarButtonItems to UINavigationItem in Storyboard?

enter image description here

It is easy to add a single UIBarButton item as you can see here in my Storyboard. But I want to add several and it seems I cannot using the Storyboard?

Which is annoying because then I lose the whole nice overview of the Storyboard and it's Segue's.

Is this the case? First project using Storyboards so I figured I might be missing something.

Upvotes: 22

Views: 6972

Answers (3)

Daniel
Daniel

Reputation: 9040

In Xcode 7 you can finally just drag multiple UIBarButtonItems to the UINavigationItem directly in Interface Builder.

See WWDC 2015 Session 407 video titled:

Implementing UI Designs in Interface Builder

https://developer.apple.com/videos/wwdc/2015/?id=407

Upvotes: 3

Rogerio Silva
Rogerio Silva

Reputation: 1

Try this

    -(void)viewDidLoad
{

    [super viewDidLoad];

    UIBarButtonItem *editBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editAction)];

    UIBarButtonItem *saveBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveAction)];

    self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:editBarButtonItem, saveBarButtonItem, nil];   
} 

We also need to implement the methods editAction and saveAction.

-(void)editAction
{

    NSLog(@"edit button clicked");
}

-(void)saveAction
{

    NSLog(@"save button clicked");
}

Upvotes: -1

Dan L
Dan L

Reputation: 526

In XCode 4.6 (at least), you can drag a plain view onto the navigation bar (on whichever side you want multiple buttons), then drag a toolbar on top of that. Once you've done that, you can place multiple bar button items on the toolbar, and wire them up to actions / segues, etc, as normal. Make sure you have the view and toolbar both set up for default (transparent) background color.

Upvotes: 51

Related Questions