Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - UINavigationController adding multiple right items?

I have a UINavigationController. I'm trying to add multiple buttons on the right side of my navigationBar. How can I achieve this? What kind of button does it take? UIBarButton or UINavigationItem?

like image 464
aryaxt Avatar asked Jul 30 '11 19:07

aryaxt


4 Answers

As of iOS5 you can assign an array of bar button items to the navigation item's rightBarButtonItems (note the plural) property.

like image 65
jrturton Avatar answered Nov 05 '22 05:11

jrturton


I used JRTurtons answer in Xcode 4.5, iOS 6 and implemented it like this and it works:

// Two buttons at the right side of nav bar
UIBarButtonItem *addAttachButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAttachmentClicked:)];
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:LS(@"Send") style:UIBarButtonItemStyleBordered target:self action:@selector(sendClicked:)];
self.navigationItem.rightBarButtonItems = @[addAttachButton,sendButton];

However, I should mention, that UIBarButtonSystemItemPageCurl doesn't work like that.

like image 24
Denis Kutlubaev Avatar answered Nov 05 '22 06:11

Denis Kutlubaev


I am sure I read in the developer reference that additional buttons in the navigation bar is frowned upon. I cannot find that passage now. I have not done it myself, but found this link that seems to outline exactly what you need to do: (http://www.mattdipasquale.com/blog/2010/11/02/how-to-add-multiple-uibarbuttonitems-to-uinavigationbar/)

Have you considered using the toolbar property of the navigation controller?

like image 14
Dean Davids Avatar answered Nov 05 '22 04:11

Dean Davids


adding any design to the navigation controller in XCode is easy.

add a UIView to your scene add the buttons you need to the UIView then drag and drop the UIView to the right space in the navigationController

like image 1
mihai Avatar answered Nov 05 '22 05:11

mihai