0

I create six (6) UIImageView's and add them to the view. I then create a timer running at 0.01 second intervals and incrementing the number by a set amount. Every so often the numbers just stop changing. Below is a sample of the code I'm running to better show what I'm doing.

 NSTimer *newTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(numberTimerFired:) userInfo:nil repeats:YES]];
 [newTimer fire];

 // Assume that I've created six (6) UIImageView's and stored them in an array called digitImageViewArray (the right most UIImageView would be index 5)
 - (void)numberTimerFired:(NSTimer *)newTimer
 {
      // self.currentNumber is the NSInteger property that is incremented each repetition
      int tempScore = self.currentNumber;
      int currentDigit = 5;

      do {

           int digit = tempScore % 10;
           tempScore /= 10;

           [[self.digitImageViewArray objectAtIndex:currentDigit] setImage:[self.numberImageArray objectAtIndex:digit]];

           currentDigit--;
      } while (tempScore !=0);

      self.currentNumber += 133; // 133 can be any number to increment by
 }

I have other conditions setup to stop the timer when the number reaches the final number. As I said, as this number goes up, whether the final number is 999,999 or 50,000 it just freezes intermittently as it rises. Any help would be greatly appreciated!

I also checked the Profile and watch CPU / memory usage. It's not even breaking 35% CPU and the memory usage is very insignificant. I've tried several fixes, such as adjusting the time interval the NSTimer runs at. However, if I leave the screen after it runs and come back… it runs smoothly with no glitching.

John Snurr
  • 95
  • 1
  • 1
  • 6
  • Is it a memory issue? XCode can monitor things like how much RAM the device is using. Also, you don't seem to be properly setting `currentDigit`. – nhgrif Dec 15 '13 at 14:32
  • int currentDigit =5; is how that line should look. – John Snurr Dec 15 '13 at 16:31
  • It looks like you're trying to do animation using UIImageViews. Instead of manually setting the image, you should use the provided mechanisms for animated images. See this question for more info: http://stackoverflow.com/questions/8545154/is-it-possible-to-animate-an-uiimage – gdavis Dec 15 '13 at 20:42
  • It also appears like you are storing all of your `UIImage` objects into a single array. If you are creating to up 1M images, or even 50,000, that is very bad usage of memory. If you truly need to load that many images, they should be loaded in batches, and not all stored into a single array creating huge memory bloat if only 6 of those images are ever displayed. – gdavis Dec 15 '13 at 20:46

0 Answers0