如何向导航栏添加项目

发布于 2024-09-30 03:32:47 字数 543 浏览 3 评论 0原文

我是 iPhone 开发新手。

通过使用上面的源代码

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

self.navigationItem.rightBarButtonItem = saveButton;

,我可以创建导航 rightbarbuttonitem 但我无法添加更多项目...我需要添加更多按钮

请为我提供一个示例代码来尝试一下

感谢您的任何帮助并感谢您的时间

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装迷糊 2024-10-07 03:32:47

将工具栏添加到导航栏

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

祝一切顺利。

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.

深陷 2024-10-07 03:32:47

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

Use DDActionHeaderView. You can add and manage items easily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文