简体   繁体   English

使用带有两个参数的UIButton addTarget时无法识别的选择器

[英]Unrecognized selector when using UIButton addTarget with two parameters

When the method that I am trying to link to my UIButton only has one parameter, then I am able to call addTarget and my code runs successfully when the button is clicked -- 当我尝试链接到我的UIButton的方法只有一个参数时,那么我可以调用addTarget,并且单击按钮时我的代码可以成功运行-

[ myDetailButton addTarget:self action:@selector(hideMap:) forControlEvents:UIControlEventTouchUpInside];

(void)hideMap:(NSMutableArray*)arguments

but if I add a second parameter to my hideMap method, I get an unrecognized selector error when calling it: 但是,如果我在hideMap方法中添加了第二个参数,则在调用它时会出现无法识别的选择器错误:

[ myDetailButton addTarget:self action:@selector(hideMap:) forControlEvents:UIControlEventTouchUpInside];

(void)hideMap:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options

I see this error no matter how I format the addTarget parameters, per this question -- 无论我如何格式化addTarget参数,我都会看到此错误,每个问题 -

action:@selector(hideMap)
action:@selector(hideMap:)
action:@selector(hideMap:event:)

How can I call a method that has multiple parameters using addTarget? 如何使用addTarget调用具有多个参数的方法?

You're problem is you are giving a selector that is expecting an NSMutableArray as the input along with a dictionary. 您的问题是您要提供一个选择器,该选择器期望将NSMutableArray与字典一起作为输入。 the UIButton does not agree with this. UIButton与此不同。 As per your post you linked to, a UIBUtton only agrees to sending either nothing, itself as an id, or itself and an event. 根据您链接到的帖子,UIBUtton只同意不发送任何内容,本身作为id或自身和事件。

I'm not 100% sure how you are expecting to get an NSMutableArray and an NSMutableDictionary from a UIButton callback, what is it exactly you are trying to achieve here, I might be able to suggest some help. 我不是100%不确定您期望如何从UIButton回调中获取NSMutableArray和NSMutableDictionary,您在此试图实现的确切目的是什么,我也许可以提出一些帮助。

The issue is your method is: 问题是您的方法是:

-(void)hideMap:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options

And the method name is hideMap:withDict: not hideMap:event: . 方法名称是hideMap:withDict:而不是hideMap:event:

Change this code action:@selector(hideMap:event:) to action:@selector(hideMap:withDict:) it'll resolve your issue. 将此代码action:@selector(hideMap:event:)更改为action:@selector(hideMap:withDict:)即可解决您的问题。

There is no method like: hideMap:event: that is the issue. 没有像这样的方法: hideMap:event:这就是问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在新的ViewController中使用代码时,UIButton无法识别的选择器发送到实例 - UIButton unrecognized selector sent to instance when using code in new ViewController iPhone-无法识别的选择器,“可能无法响应addTarget” - iPhone - Unrecognized Selector, “may not respond to addTarget” 在子视图中使用UITableView时无法识别的选择器 - Unrecognized Selector when Using UITableView in a Subview UIButton视图无法识别的选择器已发送到实例 - UIButton view unrecognized selector sent to instance 将UIButton添加到UITextField导致发送无法识别的选择器 - adding UIButton to UITextField causing unrecognized selector sent 即使选择器存在,UIButton选择器也会抛出“无法识别的选择器” - UIButton selector is throwing 'unrecognized selector' even though selector exists UIbutton框架和addtarget不同 - UIbutton frame and addtarget is different iPhone UIButton addTarget不起作用 - iPhone UIButton addTarget not working 使用UIAlertView时,奇怪的SIGABRT(无法识别的选择器发送到实例) - Weird SIGABRT (unrecognized selector sent to instance) when using UIAlertView [NSCFString objectAtIndex:]:使用nsmutabledictionery时,无法识别的选择器发送到实例 - [NSCFString objectAtIndex:]: unrecognized selector sent to instance when using nsmutabledictionery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM