I have an odd question here. I have two animations set up for a simple page flip. I then have a button that randomly generates a 1 or a 0. If the number is 0 then it performs one animation, if its 1 it performs another.
The issues I’m seeing is that this all runs fine on the simulator, but on the device it doesn’t perform the animation if the random number is 0.
Any clues?
-(IBAction)pageTurn:(id)sender {
int randomNumber = arc4random() %2;
NSLog(@"randomNumber = %d", randomNumber);
if (randomNumber == 0) {
[self turnPageForward];
} else {
[self turnPageBackward];
}
}
-(void)turnPageForward {
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"PageTurnOne.png"],
[UIImage imageNamed:@"PageTurnTwo.png"],
[UIImage imageNamed:@"PageTurnThree.png"],
[UIImage imageNamed:@"PageTurnFour.png"],
[UIImage imageNamed:@"PageTurnFive.png"],
[UIImage imageNamed:@"PageTurnSix.png"],
[UIImage imageNamed:@"PageTurnSeven.png"],
[UIImage imageNamed:@"PageTurnEight.png"],
[UIImage imageNamed:@"PageTurnNine.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 480)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = .5; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
[self.view addSubview:myAnimatedView];
[myAnimatedView release];
}
-(void)turnPageBackward {
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"PageTurnNine.png"],
[UIImage imageNamed:@"PageTurnEight.png"],
[UIImage imageNamed:@"PageTurnSeven.png"],
[UIImage imageNamed:@"PageTurnSix.png"],
[UIImage imageNamed:@"PageTurnFive.png"],
[UIImage imageNamed:@"PageTurnFour.png"],
[UIImage imageNamed:@"PageTurnThree.png"],
[UIImage imageNamed:@"PageTurnTwo.png"],
[UIImage imageNamed:@"PageTurnOne.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 480)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = .5; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
[self.view addSubview:myAnimatedView];
[myAnimatedView release];
}
Usually, when code fails on the device but not the simulator (or vice versa) the culprit is a library or other compiled source that was compiled for one hardware but not the other.
Another related possibility is that a resource was not added properly so that it is not included in the final build for the device. I would check the image files in the method that does not work.
You should also confirm if the
turnPageForwardis being called at all. That will give you a clue as to where the problem lays.