views:

33

answers:

1

Dear developers,

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

+2  A: 

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.

Warrior