Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding two right bar button items to the navigation bar

I have a navigation bar to which I have added right BarButton successfully. Both the NavigationBar and BarButton are created programmatically. Now according to my requirement I got to add two right BarButtons to my navigation Bar. Can anyone tell me how to do this? My app is targeting ios4.

like image 755
Raj Avatar asked Aug 27 '12 06:08

Raj


People also ask

How do I add a button to my navigation bar?

Example ExplainedUse any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.

How do I add a navigation bar in Swift?

Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.


2 Answers

This code will do the trick for you,

 NSArray *barButtonItems= [[NSArray alloc] initWithObjects:self.addButton,self.sortbyButton,nil];
self.navigationItem.rightBarButtonItems=barButtonItems;

where addButton and sortbyButton are 2 separate BarButton Items

like image 191
Shantanu Avatar answered Nov 23 '22 12:11

Shantanu


I know it is too late but I faced it recently. So here is what I did Create a UIView in code and add the buttons as subviews into this view. Create a ToolbarButton using [[UIBarButtonItem alloc] initWithCustomView:buttons]

Assign this toolbar button as the Left or right barbuttonItem as U wish.

like image 33
Siby Avatar answered Nov 23 '22 12:11

Siby