【问题标题】:Different results of two addTarget:action:forControlEvent: calls两个 addTarget:action:forControlEvent: 调用的不同结果
【发布时间】:2012-04-11 13:42:09
【问题描述】:

代码只不过是一个按钮的target-action

[subButton addTarget:self
              action:@selector(pickerviewSubButtonClicked:) 
    forControlEvents:UIControlEventTouchUpInside];

//[subButton addTarget:self action:@selector(pickerViewSubButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

我的第一个 失败 错误“...无法识别的选择器发送到实例...”,在使用标记的选择器时,将 成功。我怀疑它是由 通过排版,但不知道确切原因。这是他们的十六进制转储

00000000: 5b73 7562 4275 7474 6f6e 2061 6464 5461  [subButton addTa
00000010: 7267 6574 3a73 656c 660a 0920 2020 6163  rget:self..   ac
00000020: 7469 6f6e 3a40 7365 6c65 6374 6f72 2870  tion:@selector(p
00000030: 6963 6b65 7276 6965 7753 7562 4275 7474  ickerviewSubButt
00000040: 6f6e 436c 6963 6b65 643a 2920 0a09 2020  onClicked:) ..  
00000050: 2066 6f72 436f 6e74 726f 6c45 7665 6e74   forControlEvent
00000060: 733a 5549 436f 6e74 726f 6c45 7665 6e74  s:UIControlEvent
00000070: 546f 7563 6855 7049 6e73 6964 655d 3b0a  TouchUpInside];.
00000080: 2f2f 5b73 7562 4275 7474 6f6e 2061 6464  //[subButton add
00000090: 5461 7267 6574 3a73 656c 6620 6163 7469  Target:self acti
000000a0: 6f6e 3a40 7365 6c65 6374 6f72 2870 6963  on:@selector(pic
000000b0: 6b65 7256 6965 7753 7562 4275 7474 6f6e  kerViewSubButton
000000c0: 436c 6963 6b65 643a 2920 666f 7243 6f6e  Clicked:) forCon
000000d0: 7472 6f6c 4576 656e 7473 3a55 4943 6f6e  trolEvents:UICon
000000e0: 7472 6f6c 4576 656e 7454 6f75 6368 5570  trolEventTouchUp
000000f0: 496e 7369 6465 5d3b 0a                   Inside];.

有什么想法吗?

【问题讨论】:

    标签: ios button target-action


    【解决方案1】:

    你有一个错字vV

    选择器 v iewSubButtonClicked

    Objective-C 是区分大小写的语言

    【讨论】:

    • 谢谢!而已!由于后面的部分“...ewSubButtonClicked:”是由 XCode 自动完成完成的,所以我相信它并且不仔细检查!它不会更正任何错字吗?
    【解决方案2】:
    [subButton addTarget:self
                  action:@selector(pickerviewSubButtonClicked:) 
        forControlEvents:UIControlEventTouchUpInside];
    
    pickerviewSubButtonClicked <-- Error
    pickerViewSubButtonClicked <-- Work
    

    【讨论】:

      【解决方案3】:

      您的操作按钮是否发送事件? 在选择器名称之后包含“:”也期望发送一个对象。

      【讨论】:

        猜你喜欢
        • 2016-12-08
        • 1970-01-01
        • 2010-09-26
        • 2019-02-12
        • 2013-08-27
        • 1970-01-01
        • 2021-12-18
        • 2020-05-19
        • 1970-01-01
        相关资源
        最近更新 更多