Reputation: 6386
I am new to iPhone development.
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
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