繁体   English   中英

如何将项目添加到导航栏

[英]how to add items to the navigation bar

我是iPhone开发的新手。

源代码

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

self.navigationItem.rightBarButtonItem = saveButton;

通过使用上面,我可以创建导航右栏按钮,但我不能添加更多项目...我需要添加更多按钮

请提供一个示例代码来试用它

感谢您的帮助和感谢您的时间

将工具栏添加到导航栏

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];

祝一切顺利。

使用DDActionHeaderView 您可以轻松添加和管理项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM