当我按下停止按钮停止计时器时,它只是重置为原始时间并再次开始倒计时。我到处寻找,我发现的只是“无效”而且它不起作用。我希望当我点击停止时时间停止并且标签显示原始时间。我还关闭了自动计数,所以我可以尝试释放,它给了我一个错误:
0x10e20a5: movl 16(%edx), %edx EXC_BAD_ACCESS (代码=2, 地址=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