0
A
答えて
0
これを試してみてください:
[ButtonName addTarget:self action:@selector(randomize) forControlEvents:UIControlEventTouchUpInside];
- (void) randomize
{
random = arc4random()%5;
switch (random)
{
case 0:
*condition*
break;
case 1:
*condition*
break;
.....
}
が、これはあなたを助けることができる願っています。
0
ボタンを押すたびに乱数が生成され、コンソールに出力されます。
- (void)viewDidLoad
{
UIButton *button = [UIButton buttonWithStyle:UIButtonStyleRoundedRect];
[button addTarget:self withAction:@selector(random) forEvent:UIControlEventTouchUpInside];
[button setFrame:CGRect(50,50,100,50);
[self.view addsubview:button];
}
- (void)random
{
NSLog(@"%i",arc4random());
}
0
あなたのボタンにIBActionを追加し、これを実行します。
- (IBAction)buttonPress:(id)sender
{
myValue = arc4random() % MAX_VALUE;
}
これは、[0、MAX_VALUE)から乱数を生成し、(int型に保管されます)を変数myValue
。