在我的代码中有 1 个按钮和 7 个 IBAction。 按钮启动各种随机数和算术运算。
现在我的问题是:如果我点击按钮,我怎么说,从:
- (IBAction)Zufallszahl1:(id)sender
然后
- (IBAction)Zufallszahl2:(id)sender
然后
等等……
我找不到解决方案。
最佳答案
不要向按钮添加 7 个 IBAction。每次按下按钮时它们都会触发。
如果您希望按钮随机执行某些操作,则可以执行一个操作来执行类似的操作...
- (IBAction)randomButtonEvent
{
// if you want random then...
NSInteger methodNumber = arc4random_uniform(7);
// if you want to increment each time then have a property methodNumber
self.methodNumber += 1;
if (self.methodNumber == 7) {
self.methodNumber = 0;
}
switch methodNumber { // or self.methodNumber
case 0:
// do your first action
break;
case 1:
// do your second action
break;
case 2:
// do your third action
break;
// you get the picture
}
}
这将有一个按钮事件,随机运行七种方法之一。
关于ios - 1 个按钮有 4 个操作,我可以按特定顺序对操作进行排序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235013/