NSTimer won't stop it only resets when invalidated & released

Posted by J Fries on Stack Overflow See other posts from Stack Overflow or by J Fries
Published on 2012-10-21T04:56:10Z Indexed on 2012/10/21 5:00 UTC
Read the original article Hit count: 110

Filed under:
|
|
|

When I press my stop button to stop the timer it just resets to the original time and begins counting down again. I have looked everywhere and all I have found is "invalidate" and it isn't working. I want the time to stop when I hit stop and the label to display the original time. I also turned off automatic counting so I could try releasing and it is giving me an error: 0x10e20a5: movl 16(%edx), %edx EXC_BAD_ACCESS (code=2, address=0x10)

`NSTimer *rockettTimer;
int rocketCount;

@interface FirstViewController ()
@property (strong, nonatomic) IBOutlet UILabel *rocketTimer;

- (IBAction)stopButton:(id)sender;
- (IBAction)startButton:(id)sender;

@end

@implementation FirstViewController
@synthesize rocketTimer;

-(void) rocketTimerRun{
rocketCount = rocketCount - 1;
int minuts = rocketCount / 60;
int seconds = rocketCount - (minuts * 60);
NSString *timerOutput = [NSString stringWithFormat:@"%d:%.2d", minuts, seconds];
rocketTimer.text = timerOutput;
}

- (IBAction)startButton:(id)sender {

rocketCount = 180;
rockettTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self    selector:@selector(rocketTimerRun) userInfo:nil repeats:YES];

- (IBAction)stopButton:(id)sender {
[rockettTimer invalidate];
//[rockettTimer release];
}

- (void)viewDidLoad
{


[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
[self setRocketTimer:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}

 - (BOOL)shouldAutorotateToInterfaceOrientation:  (UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}


@end`

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios