基于对象生成的随机数触摸事件

时间:2013-06-03 06:27:22

标签: ios objective-c touch

int rand=((arc4random()%4)+1);

由于touch event生成的数字,您将如何制作int rand

示例,如果生成的数字为1,2,2,3,4,而您的4 buttons标记为1,2,3,4

如何按照int rand方法生成的数字顺序触摸对象?如何制作事件?

1 个答案:

答案 0 :(得分:0)

让4个按钮给出一个动作

- (void)touchesBegan:(NSSet *)触及withEvent:(UIEvent *)事件

{

rand=((arc4random()%4)+1);

}

- (IBAction为)myMethod的     {

switch (rand)
{

case 1:
//Do for first button tag
break;

case 2:
//Do for second button tag
break;

case 3:
//Do for third button tag
break;

case 4:
//Do for fourth button tag
break;


default:
break;
}

}