11から20の間の乱数を生成してボタンに保存する必要があります。乱数が生成されるたびに、乱数が12の場合、iPhoneで2つの画像がスワイプされるたびに乱数が発生し、画像が12回スワイプされてからスワイプされます停止。
乱数を生成しましたが、画像を乱数でスワイプできません。
これが私のコードです
-(IBAction)btngeneratePressed:(id)sender{
number = 1 + arc4random() % 10 + 10;
for (int j=1;j<number-1;j++) // generate unique random number only once
{
NSArray *myImageNames = [NSArray arrayWithObjects:@"1.png", @"2.png", nil];
//int index = arc4random() % [myImageNames count];
int index = arc4random() % 2;
UIImage *myImage = [UIImage imageNamed:[myImageNames objectAtIndex:index]];
img.image = myImage;
if(number == j){
NSLog(@"Number %d ",j);
UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"Rendom number" message: @"Image swip" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[someError show];
[someError release];
break;
}
}
}
- (void)viewDidLoad
{
number = 1 + arc4random() % 10 + 10;
NSString *string=[NSString stringWithFormat:@"%i",number];
int p=string;
label.text = string;
for(int j=1;j<number-1;j++)
{
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(btngeneratePressed:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
recognizer.numberOfTouchesRequired = 1;
recognizer.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:recognizer];
[recognizer release];
//Add a right swipe gesture recognizer
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(btngeneratePressed:)];
recognizer.numberOfTouchesRequired = 1;
recognizer.delegate = self;
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
if(number == j){
NSLog(@"Number %d ",j);
UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"Rendom number" message: @"Image swip" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[someError show];
[someError release];
break;
}
}
}