views:

153

answers:

1

The code I wrote for 3.2 performs differently in OS4. Still no errors, just new bugs.

So I'm initializing the imageView inside an IBAction called "randomize" that produces and random number that goes to one of 86 cases producing a resulting animation and image, the only difference in code between 0 and 86 is that final imageView.image (I just didn't want to past 86 copies of the same code in for you to have to wade through ). No matter what the case, the animation imageView.animationImages runs. The bug is that the first time I run the action, imageView.animationImages runs showing my animation, then instead of completing the code and going to the imageView.image = [UIImage imageNamed:@"image36.png"], it now just shows whatever I have set as the actual imageView background in Interface Builder. And Sometimes it runs the animation for one case and the imageview.image for another. Any ideas?

- (IBAction)randomize {
 int Number = arc4random() % 86;
 switch (Number) {
      case 0:
           imageView.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"image1.png"],
                                               [UIImage imageNamed:@"image2.png"],
                                               [UIImage imageNamed:@"image3.png"],
                                               [UIImage imageNamed:@"image4.png"],
                                               [UIImage imageNamed:@"image5.png"],
                                               [UIImage imageNamed:@"image6.png"],
                                               [UIImage imageNamed:@"image7.png"],
                                               [UIImage imageNamed:@"image8.png"],
                                               [UIImage imageNamed:@"image9.png"],
                                               [UIImage imageNamed:@"image10.png"],
                                       [UIImage imageNamed:@"image0.png"],nil];
           imageView.animationDuration = 0.50;
           [imageView setAnimationRepeatCount: 1];
           [imageView startAnimating]; 
           imageView.image = [UIImage imageNamed:@"image36.png"];

           break;
      case 1:
           imageView.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"image1.png"],
                                               [UIImage imageNamed:@"image2.png"],
                                               [UIImage imageNamed:@"image3.png"],
                                               [UIImage imageNamed:@"image4.png"],
                                               [UIImage imageNamed:@"image5.png"],
                                               [UIImage imageNamed:@"image6.png"],
                                               [UIImage imageNamed:@"image7.png"],
                                               [UIImage imageNamed:@"image8.png"],
                                               [UIImage imageNamed:@"image9.png"],
                                               [UIImage imageNamed:@"image10.png"],
                                       [UIImage imageNamed:@"image0.png"],nil];
           imageView.animationDuration = 0.50;
           [imageView setAnimationRepeatCount: 1];
           [imageView startAnimating]; 
           imageView.image = [UIImage imageNamed:@"image37.png"];

           break;
A: 

If I had to guess, you're missing break statments at random intervals in your 86 cases. Please consider refactoring to a method...

Joshua Weinberg