首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在UIBarButtonItem中向rightBarButtonItem中添加多个rightBarButtonItem?

如何在UIBarButtonItem中向rightBarButtonItem中添加多个rightBarButtonItem?
EN

Stack Overflow用户
提问于 2013-09-26 07:01:53
回答 1查看 5.1K关注 0票数 1

我有一个在ios6中运行良好的现有代码。但在ios7中,大多数项目(“刷新按钮”)都没有显示与其他两个UIBarButtonItem对齐。它几乎没有表现出来。这是iOS6的代码。在iOS7中,我需要进行哪些更改才能使其发挥作用。

代码语言:javascript
复制
 // create an array for the buttons
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

// create a standard save button
UIBarButtonItem* refreshButton = [[UIBarButtonItem alloc]
                                  initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                  target:self
                                  action:@selector(refreshButtonClicked:)];

refreshButton.style=UIBarButtonItemStyleBordered;
//self.navigationItem.rightBarButtonItem = refreshButton;

[buttons addObject:refreshButton];
[refreshButton release];

// create a spacer between the buttons
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                           target:nil
                           action:nil];

[buttons addObject:spacer];
[spacer release];

// create a standard delete button with the trash icon
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
[button setFrame:CGRectMake(0, 0, 30, 30)];

[button addTarget:self action:@selector(InfoButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

infoItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[buttons addObject:infoItem];

// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:NO];
[buttons release];

// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
                                           initWithCustomView:toolbar]autorelease];

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-26 07:50:43

尝试:

self.navigationItem.rightBarButtonItems = buttons;

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19021486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档