I have a tap counter and this is the “Who Wins” code. The app is crashing whenever Flipped (int timer) is equal to 30 and it is deciding who had the most taps. It always says “Player 2 Wins” and freezes. Please help. Number is the number value of one tapper, Number1 is the value of the second tapper. How do I fix this?
- (void)countup
{
if (Fliped == 30)
{
//error message
if (Number < Number1)
{
myAlertView = [[UIAlertView alloc] initWithTitle:@"Stop!" message:@"Player 2 Wins!" delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
timer = [NSTimer scheduledTimerWithTimeInterval:0.0
target:self selector:@selector(countup)userInfo:nil repeats:YES];
[myAlertView show];
}
if (Number > Number1)
{
myAlertView = [[UIAlertView alloc] initWithTitle:@"Stop!" message:@"Player 1 Wins!" delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
timer = [NSTimer scheduledTimerWithTimeInterval:0.0
target:self selector:@selector(countup)userInfo:nil repeats:YES];
[myAlertView show];
}
else
{
MainInt += 1;
seconds.text = [NSString stringWithFormat:@"%d", MainInt];
Fliped += 1;
secondsFlip.text = [NSString stringWithFormat:@"%d", Fliped];
}
}
Thanks in advance.
what could be the cause of this crash???
You’re calling your own method
countuprecursively an infinite number of times when the variableFlipedis 30. That’s why you’re crashing. Don’t do that.