我是iPhone开发的新手。
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"SAVE"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(saveButtonClicked)];
self.navigationItem.rightBarButtonItem = saveButton;
通过使用上面的,我可以创建导航右栏按钮,但我不能添加更多项目...我需要添加更多按钮
请提供一个示例代码来试用
感谢您的帮助和感谢您的时间
答案 0 :(得分:6)
将工具栏添加到导航栏
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];
一切顺利。
答案 1 :(得分:0)
使用DDActionHeaderView。您可以轻松添加和管理项目。