有人知道如何使用 IBOutletCollection 设置按钮数组中每个按钮的标题吗?这是我尝试过的,但代码设置了所有按钮的标题。我已将插座连接到按钮并设置它们各自的标签。
.h file
@property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttonCollection;
.m file
- (IBAction)switchAction:(id)sender {
for (UIButton *btn in buttonCollection) {
if (btn.tag == 0) {
[btn setTitle:@"1st Button" forState:UIControlStateNormal];
} else if (btn.tag == 1) {
[btn setTitle:@"2nd Button" forState:UIControlStateNormal];
} else if (btn.tag == 2) {
[btn setTitle:@"3rd Button" forState:UIControlStateNormal];
}
}