正在从UIButtons的IBOutletCollection检索标记



我有一个UIButtons的IBOutletCollection。检索按钮的mutableArray中任何索引的标记的最有效方法是什么。

@property(retain) IBOutletCollection(UIButton) NSMutableArray *emptySpaces;

这就是我的按钮被声明为的方式

@property (strong, nonatomic) IBOutlet UIButton *position1;

我试过以下几种。我做错了什么?谢谢

if(emptySpaces[0].tag == 1){
}

 if([emptySpaces objectAtIndex:0].tag == 1){
  }

要回答您的初始问题,NSMutableArray -objectAtIndex:返回的id没有名为tag的接收器。在发送标记消息之前,您应该首先将结果强制转换为UIButton。像这样:((UIButton *)self.emptySpaces[0]).tag

你可以试试这样的东西:

for (UIButton *button in self.emptySpaces) {
    if (button.tag == 1) {
    }
}

最新更新