带参数的选择器 [英] Selector with argument

查看:47
本文介绍了带参数的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的方法:

I have a method like this:


- (void)methodWithParameter:(id)parameter {

}

我想使用UIBarButtonItem调用它

and I want to call it using an UIBarButtonItem


barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(methodWithParameter:)];

我想指定参数,但不能在操作后使用withObject :,因为得到警告:

I want to specify the parameter but I can't use withObject: after action: because I get a warning:

找不到-initWithBarButtonSystemItem:target:action:withObject:方法
No -initWithBarButtonSystemItem:target:action:withObject: method found

有人可以帮我吗?

推荐答案

它不能那样工作.您不能将参数传递给操作.动作方法将始终具有以下任一条件:

It doesn't work that way. You cannot pass a parameter to an action. An action method will always have either:

  • 一点也不争论,
  • 一个参数(id)sender
  • 或两个参数(id)sender (UIEvent *)event .

这篇关于带参数的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆