so im trying to make a rock paper scissors app activated by either a button or the accelerometer by first doing a short animation which cycles through the three, then display a random image (1 of the 3) at the end of the animation. The animation itself works perfectly fine, but after it finishes the random image does not show.
UIImageView *image;
int x = arc4random() % 3 + 1;
NSString *imageName =开发者_JAVA技巧 [NSString stringWithFormat:@"image%d.jpg", x];
UIImage *img = [UIImage imageNamed:imageName];
It looks like you're not initializing your UIImageView
. Also, for the random image, I recommend this code: (it's more flexible)
NSArray*images = rockpaperscissorsView.animationImages;
NSUInteger randomIndex = arc4random() % [images count];
UIImage*randomImage = [images objectAtIndex:randomIndex];
UIImageView*image = [[UIImageView alloc] initWithImage:randomImage];
Don't forget to release image
once you're done with it.
精彩评论