gpt4 book ai didi

iphone - 导航栏上有超过 1 个 rightBarButtonItem

转载 作者:行者123 更新时间:2023-12-03 18:17:22 25 4
gpt4 key购买 nike

我想在导航栏上有两个 rightBarButtonItems。一个用于编辑,另一个用于添加。

显然我无法使用 Interface Builder 来实现它。

有人知道如何以编程方式做到这一点吗?谢谢!

最佳答案

它现在包含在 iOS 5 中,称为 rightBarButtonItems,注意复数

这是来自 apple docs 的文本:

rightBarButtonItems

An array of custom bar button items to display on the right side of the navigation bar when the receiver is the top navigation item.

@property(nonatomic, copy) NSArray *rightBarButtonItems

Discussion

This array can contain 0 or more bar button items to display on the right side of the
navigation bar. Items are displayed right-to-left in the same order as they appear in the array. Thus, the first item in the array is the rightmost item and other items are added to the left of the previous item.

If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the left side of the bar are not
displayed.

The first item in the array can also be set using the rightBarButtonItem property.

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

关于iphone - 导航栏上有超过 1 个 rightBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/931457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com