[英]UIButton unrecognized selector sent to instance when using code in new ViewController
[英]Unrecognized selector when using UIButton addTarget with two parameters
當我嘗試鏈接到我的UIButton的方法只有一個參數時,那么我可以調用addTarget,並且單擊按鈕時我的代碼可以成功運行-
[ myDetailButton addTarget:self action:@selector(hideMap:) forControlEvents:UIControlEventTouchUpInside];
(void)hideMap:(NSMutableArray*)arguments
但是,如果我在hideMap方法中添加了第二個參數,則在調用它時會出現無法識別的選擇器錯誤:
[ myDetailButton addTarget:self action:@selector(hideMap:) forControlEvents:UIControlEventTouchUpInside];
(void)hideMap:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
無論我如何格式化addTarget參數,我都會看到此錯誤,每個問題 -
action:@selector(hideMap)
action:@selector(hideMap:)
action:@selector(hideMap:event:)
如何使用addTarget調用具有多個參數的方法?
您的問題是您要提供一個選擇器,該選擇器期望將NSMutableArray與字典一起作為輸入。 UIButton與此不同。 根據您鏈接到的帖子,UIBUtton只同意不發送任何內容,本身作為id或自身和事件。
我不是100%不確定您期望如何從UIButton回調中獲取NSMutableArray和NSMutableDictionary,您在此試圖實現的確切目的是什么,我也許可以提出一些幫助。
問題是您的方法是:
-(void)hideMap:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
方法名稱是hideMap:withDict:
而不是hideMap:event:
將此代碼action:@selector(hideMap:event:)
更改為action:@selector(hideMap:withDict:)
即可解決您的問題。
沒有像這樣的方法: hideMap:event:
這就是問題所在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.