如何调用NSArray中的UIButton方法?

问题描述:

我想启用一个按钮,但我会启用此功能的按钮更改。我有一个按钮的数组,但是当我在数组索引上使用.enabled时,我想它说这不适用于ID。如何调用NSArray中的UIButton方法?

我已经使用这个数组使用前设置每个按钮上的文字:

[[ButtonArray objectAtIndex: Index] setTitle:(@"blahblahblah") forState: UIControlStateNormal]; 

有没有办法使用类似的函数调用来启用和禁用?

+0

备注 - 类名以大写字母开头。变量和方法名称应以小写字母开头。这是许多(大多数?)开发人员使用的标准惯例。 – rmaddy

如果你肯定知道的一切,阵列是一个UIButton你可以施放它使编译器高兴:

[(UIButton *)[ButtonArray objectAtIndex: Index] setTitle:(@"blahblahblah") forState: UIControlStateNormal]; 
+0

好的,但我想要的是将按钮更改为启用,我知道它为setTitle工作。 – user1792818

+0

你调用的是哪种'UIButton'方法并不重要,如果问题是你被告知“这不适用于ID”,演员将摆脱警告。 –

这是确定多达拆分代码为多行。它使读取,调试和维护更加容易。

UIButton *button = ButtonArray[Index]; // new, modern array syntax 
button.enabled = YES; 
[button setTitle:@"blah" forState:UIControlStateNormal]; 
+0

感谢您的帮助,我的问题实际上是当我想要YES时将设置为NO,我觉得很愚蠢。 – user1792818