2013-06-03 26 views
0
int rand=((arc4random()%4)+1); 

由於從int rand生成的數字,您將如何着手製作touch event基於物體上產生的隨機數的觸摸事件

示例如果生成的數字是1,2,2,3,4並且您有4 buttons且標籤爲1,2,3,4

您將如何進行事件,您必須按int rand方法生成的編號順序觸摸對象?

回答

0

使4個按鈕給oneaction

- (無效)的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; 
} 

}