[英]1 Button with 4 actions, can I sort the actions in a specific order?
在我的代码中是带有7个IBAction的1 Button。 该按钮启动各种随机数和算术运算。
现在我的问题是:如果我按下按钮,我该怎么说:
- (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
}
}
这将具有一个按钮事件,该事件将随机运行七个方法之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.