为 UIBarButtonItem 的 rightBarButtonItem 调用的委托方法

发布于 2024-10-17 01:27:46 字数 73 浏览 6 评论 0原文

点击 UIBarButtonItem 的 rightBarButtonItem 时调用的委托方法是什么?我想在那里实施一项具体行动。

What is the delegate method called when rightBarButtonItem of UIBarButtonItem is tapped? I want to implement a specific action there.

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

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

发布评论

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

评论(2

喵星人汪星人 2024-10-24 01:27:46

没有预定义的委托方法。您需要设置委托/操作(类似于 UIControl)。例如,按以下方式在 viewDidLoad 中创建 UIBarButtonItem:

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Mark"                               style:UIBarButtonItemStylePlain  target:self action:@selector(actionForTap:) autorelease];

并在视图控制器中实现 actionForTap: 。如果您已经有了 UIBarButtonItem,您可以将目标/操作设置为您想要的委托方法的目标/操作,例如:

self.navigationItem.rightBarButtonItem.target = self;
self.navigationItem.rightBarButtonItem.action = @selector(actionForTap:);

作为第三种方法,您可以在 IB 中配置它(但我不会去那里)。

There is no predefined delegate method. You need to set the delegate/action (similar to a UIControl). For example, create the UIBarButtonItem in viewDidLoad the following way:

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Mark"                               style:UIBarButtonItemStylePlain  target:self action:@selector(actionForTap:) autorelease];

and implement actionForTap: in your view controller. If you already have the UIBarButtonItem you can set the target/action to those of your desired delegate method, e.g.:

self.navigationItem.rightBarButtonItem.target = self;
self.navigationItem.rightBarButtonItem.action = @selector(actionForTap:);

As a third way, you can configure it in IB (but I'm not going there).

云淡月浅 2024-10-24 01:27:46

您不需要任何委托方法。您可以简单地使用下面的代码。
这是简单地在右侧添加一个按钮并向该按钮添加一个操作的代码。
就我而言,我调用了名为“AddButtonMethod”的方法。

UIBarButtonItem *AddButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddButtonMethod:)];
self.navigationItem.rightBarButtonItem = AddButton;

You don't need any delegate method. You can simply use the below code.
This is code for simply adding a button on the right and adding an action to that button.
In my case I called the method named "AddButtonMethod".

UIBarButtonItem *AddButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddButtonMethod:)];
self.navigationItem.rightBarButtonItem = AddButton;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文