Hey guys. I have a count up timer that counts to 10 and when it is at 10 it plays a sound. It works and all. My problem is when it gets to 10, the timer is supposed to stop and reset at zero but go no further until the button is pressed again. Right now it counts to 10 and then loops back to 0 and continues to 10 again.
here is my code:
Code:
// TIMER START ----------------------
-(void)countup {
MainInt += 1;
seconds.text = [NSString stringWithFormat:@"%i", MainInt];
if (MainInt == 10) {
{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Ping", CFSTR ("aiff"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
if (MainInt >= 10) {
MainInt = -2;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(countup)userInfo:nil repeats:NO];
}
}
-(IBAction)start:(id)sender {
MainInt = 0;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(countup)userInfo:nil repeats:YES];
}
// TIMER END ------------------------