我正在尝试动态更新 s 的IBOutletCollection
标题UIButton
。我希望标题设置为
- 选择时的字母“S”和
- 禁用和选择时的文本“D|S”。
它不起作用,所以我打印了titleForState:
s ,看起来标题设置不正确。我使用setTitle: forState:
正确吗?
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *buttons;
...
- (void)updateUI // Calling this from IBAction
{
for(UIButton *button in self.buttons) {
[button setTitle:@"S" forState:UIControlStateSelected];
[button setTitle:@"D|S" forState:UIControlStateSelected|UIControlStateDisabled];
NSLog(@"%@ %@ %@ %@ %d %d",
[button titleForState:UIControlStateSelected],
[button titleForState:UIControlStateSelected],
[button titleForState:UIControlStateNormal],
[button titleForState:UIControlStateSelected|UIControlStateDisabled],
button.selected,
button.enabled);
}
}
这是控制台输出:
2013-02-21 21:05:36.070 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.072 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.073 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.073 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.073 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.074 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.074 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.074 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.075 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.075 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.076 Buttons[37130:c07] D|S D|S 0 1
2013-02-21 21:05:36.076 Buttons[37130:c07] D|S D|S 0 1