Ios 启用和禁用视图问题中的多个按钮
我有一个有12个按钮的视图。我想能够执行一次行动的按钮,当我点击它,然后设置特定的按钮禁用。当我点击另一个按钮时,我希望同样的事情发生+设置其他按钮启用。有解决方案吗?您可以给每个按钮一个标签,当您使用方法viewWithTag点击按钮时,您可以启用和禁用每个按钮: 创建UIButton时,可以添加:Ios 启用和禁用视图问题中的多个按钮,ios,ios7,Ios,Ios7,我有一个有12个按钮的视图。我想能够执行一次行动的按钮,当我点击它,然后设置特定的按钮禁用。当我点击另一个按钮时,我希望同样的事情发生+设置其他按钮启用。有解决方案吗?您可以给每个按钮一个标签,当您使用方法viewWithTag点击按钮时,您可以启用和禁用每个按钮: 创建UIButton时,可以添加: UIButton *button0 = ... button0.tag = 0; UIButton *button1 = ... button1.tag = 1; //and so on 在
UIButton *button0 = ...
button0.tag = 0;
UIButton *button1 = ...
button1.tag = 1;
//and so on
在按钮的每个动作中,必须按如下方式传递id对象:
-(void)tapButtonOne:(id)sender {
//with this sender you can retrive the tag of the button clicked
UIButton *button = sender;
int buttonTag = button.tag
//now you can check every button and enable the other that haven't the same buttonTag
//with the first tag = 0 plus 12 the last tag will be 11 so i<12
for (int i = 0; i<12; i++) {
//self.view if you have added the buttons on self.view, otherwise you must write your view
UIButton *buttonTemp = (UIButton *)[self.view viewWithTag:i];
if(buttonTemp.tag != buttonTag) {
buttonTemp.enabled = YES;
}
else {
buttonTemp.enabled = NO;
}
}
}
创建一个IBOutletCollection,而不是创建一个outlet。 当您从界面生成器拖动到应用程序时,可以将插座选择更改为插座集合。 对第一个按钮执行此操作后,控制拖动所有按钮并将它们链接到同一集合。 将所有按钮连接到同一iAction,并确保它指定发件人这是默认设置。 然后,在你的行动中:
for (UIButton* button in self.yourOutletCollection){
if (button == sender){
// this is the button that was tapped
} else {
// all the other buttons go here
}
}
享受吧 每个按钮是否有不同的动作?是否有不同的动作。确切地说,我在图像上应用过滤器