user198725878
user198725878

Reputation: 6386

how to add items to the navigation bar

I am new to iPhone development.

source code

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"SAVE" 
                                            style:UIBarButtonItemStyleBordered 
                                                              target:self 
                                         action:@selector(saveButtonClicked)];

self.navigationItem.rightBarButtonItem = saveButton;

by using the above , i can create navigation rightbarbuttonitem but i cant add more items into it...i need to add more buttons

please provide me a sample code to try it out

Thanks for any help and thanks for your time

Upvotes: 3

Views: 2197

Answers (2)

Khawar
Khawar

Reputation: 9241

Use DDActionHeaderView. You can add and manage items easily.

Upvotes: 0

Warrior
Warrior

Reputation: 39374

Add tool bar to Navigation bar

UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];
tools.tintColor = [UIColor blackColor];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];

// create a standard "add" button
 bi = [[UIBarButtonItem alloc]
                       initWithTitle:@"Add" style:UIBarButtonItemStyleBordered  target:self action:@selector(addMedicine)];

[buttons addObject:bi];
[bi release];

// create a spacer


bi = [[UIBarButtonItem alloc]
      initWithTitle:@"Edit" style:UIBarButtonSystemItemEdit target:self action:@selector(edit)];

[buttons addObject:bi];
[bi release];


// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];

[buttons release];

// and put the toolbar in the nav bar

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];

All the best.

Upvotes: 6

Related Questions