2013-02-12 70 views
1

我准备为RoundedRect类型的UIButton禁用userinteraction。我试图通过代码禁用RoundedRect类型的UIButton的用户交互

[previousAudio userInteractionEnabled:NO]; 

,但得到终止应用程序异常 由于未捕获的异常NSInvalidArgumentException,原因是:-[UIRoundedRectButton userInteractionEnabled:]:无法识别的选择发送到实例

我能做些什么,而不是禁用的用户交互?

谢谢。

回答

7

可以使用previousAudio.enabled = NO OR YES instad的[previousAudio userInteractionEnabled:NO];

+2

“使能标志与_”userInteractionEnabled“标志不同,请参阅文档以了解更多细节,但”启用“标志基本上也会影响按钮的外观。 ,那么“enabled”标志是正确的,但原始问题中的混淆是在“setUserInteractionEnabled”和“userInteractionEnabled”之间。“set”版本与[]括号符号一起使用,而后者被使用 – 2014-10-02 05:23:00

+0

@ErikvanderNeut我在我的回答中没有说你不能使用'userInteractionEnabled'我只是建议你可以使用按钮启用YES或NO因为对于按钮,如果你使用启用是不是作为标准的用户界面,你可以注意到显示用户界面可以触摸,但是当你使用userInteractionEnabled用户不能标识符是那个按钮是可触摸的或不是那个拉斯我建议启用是否 – 2014-10-02 05:32:49

+0

感谢您的澄清@Nitin。你是对的,如果你想反映按钮的外观和感觉的变化,“启用”是一个更好的选择。 - 我想澄清的是,由于您使用[previousAudio userInteractionEnabled:NO]而不是[previousAudio setUserInteractionEnabled:NO]或previousAudio.userInteractionEnabled = NO,您得到了“无法识别的选择器发送到实例”错误。只是想确保你知道点符号(我个人更喜欢)与[]括号符号之间的区别。 – 2014-10-09 01:21:26

3

它应该是:

[previousAudio setUserInteractionEnabled:NO]; 

previousAudio.userInteractionEnabled = NO; 
1

因为没有userInteractionEnabled:选择。 userInteractionEnabled是getter。为了设置属性,你应该使用button.userInteractionEnabled = NO[button setUserInteractionEnabled:NO]

-1

,你可以将其设置为desiabled previousAudio.enabled = NO或者你可以在IBAction为方法

-(IBAction)previousAudioPressed:(id)sender{ 

    if (condition){ 
      //do something 
    } 

} 
0

设置条件使用setUserInteractionEnabled:NO的代替userInteractionEnabled: NO

[previousAudio setUserInteractionEnabled:NO]; 

无论你的按钮是圆形的还是哈哈还有其他一些财产。

相关问题