相关疑难解决方法(0)

当我打电话给[Timer isValid]或[Timer invalidate]时,NSTimer崩溃了

我的iPhone应用程序中有两个NSTimers.DecreaseTimer工作正常,但是当我调用[timerCountSeconds isValid]或[timerCountSeconds invalidate]时,TimerCountSeconds崩溃.他们像这样使用:

-(id)initialize { //Gets called, when the app launches and when a UIButton is pressed
 if ([timerCountSeconds isValid]) {
  [timerCountSeconds invalidate];
 } 
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //Gets called, when you begin touching the screen
 //....
 if ([decreaseTimer isValid]) {
   [decreaseTimer invalidate];
  }
 timerCountSeconds = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(runTimer) userInfo:nil repeats:YES];
 //....
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {//Gets called, when you stop touching the screen(not if you press the UIButton for -(id)initialize)
 //...
 decreaseTimer = …
Run Code Online (Sandbox Code Playgroud)

iphone crash xcode objective-c nstimer

10
推荐指数
1
解决办法
7993
查看次数

标签 统计

crash ×1

iphone ×1

nstimer ×1

objective-c ×1

xcode ×1