Sunday 15 August 2010

ios - Random image generator by ViewDidLoad -


I created the code, so: when the view was loaded, a random image shows I wrote some code, but It always starts with the same image (and WhubGolor).

My code:

  - (zero) viewDidload {index = [NSNumber number with: ( [Index intuView + 1)% 6)]; Switch ([index intValue]) {case 0: moodImage.image = [UIImage imageNamed: @ "angry.png"]; Self.view.backgroundColor = [UIColor redColor]; break; Case 1: Mood Image Dimension = [UIImage imageNamed: @ "Disappointed.png"]; Self.view.backgroundColor = [UIColor brownColor]; break; Case 2: Mood Image Dimension = [UIImage imageNamed: @ "glad.png"]; Self.view.backgroundColor = [UIColor orange color]; break; Case 3: Mood Image Image = [UIImage Image Named: @ "Happy Page"]; Self.view.backgroundColor = [UIColor yellowColor]; break; Case 4: Mood Image Dimension = [UIImage imageNamed: @ "sad.png"]; Self.view.backgroundColor = [UIColor gray color]; break; Case 5: Mood Image. Impress = [UIImage Image Named: @ "Puzzled."] ;; Self.view.backgroundColor = [UIColor greenColor]; break; }}   

This is really disappointing. It works well with an IBAction but is not with viewdidload ... Is this work for someone to block alternative Is the code?

  index = [with NSNumber numbers: (([index intValue] + 1)% 6) ];   

This line of code has no random value.

Try it:

  Index = [NSNumber numberAttro: arc4random_uniform (5)];   

For information about random numbers in objective-c, see

No comments:

Post a Comment