加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – NSTimer崩溃,当我调用[Timer isValid]或[Timer invali

发布时间:2020-12-14 19:50:10 所属栏目:百科 来源:网络整理
导读:我的iPhone应用程序中有两个NSTimers DecreaseTimer工作正常,但是当我调用[timerCountSeconds isValid]或[timerCountSeconds invalidate]时,TimerCountSeconds崩溃.它们是这样使用的: -(id)initialize { //Gets called,when the app launches and when a UI
我的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 = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(decrease) userInfo:nil repeats:YES];
 //...
}
-(void)comept3 { //Gets calles when you rubbed the screen a bit
    if ([timerCountSeconds isValid]) {
    [timerCountSeconds invalidate];
    }
}

我做错了什么?
你能帮我么?

解决方法

您将NSTimer对象设置为nil后,将其无效,因为无效方法调用也会发布(根据Apple文档).如果不这样做,就像isValid一样调用方法可能会导致你的崩溃.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读