我想在导航栏上有两个 rightBarButtonItems。一个用于编辑,另一个用于添加。
显然我无法使用 Interface Builder 来实现它。
有人知道如何以编程方式做到这一点吗?谢谢!
它现在包含在 iOS 5 中,称为 rightBarButtonItems,注意复数
这是来自苹果文档 https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationItem_Class/Reference/UINavigationItem.html:
右栏按钮项目
显示在导航栏右侧的一组自定义栏按钮项目
当接收器位于顶部导航项时。
@property(nonatomic, 复制) NSArray *rightBarButtonItems
讨论
该数组可以包含 0 个或多个条形按钮项目,以显示在右侧
导航栏。项目按照它们在列表中出现的顺序从右到左显示
大批。因此,数组中的第一项是最右边的项,其他项被添加
到上一项的左侧。
如果没有足够的空间来显示数组中的所有项目,则那些将
与标题视图重叠(如果存在)或栏左侧的按钮不重叠
显示。
数组中的第一项也可以使用 rightBarButtonItem 属性进行设置。
在 UINavigationBar.h 中声明
以下是我在导航栏右侧实现搜索图标和编辑图标的方法:
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
target:self
action:@selector(searchItem:)];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self action:@selector(editItem:)];
self.navigationItem.rightBarButtonItems =
[NSArray arrayWithObjects:editButton, searchButton, nil];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)