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

iphone – NSTimer崩溃,当我调用[Timer isValid]或[Timer invalidate],第1张

概述我的iPhone应用程序中有两个NSTimers DecreaseTimer工作正常,但是当我调用[timerCountSeconds isValid]或[timerCountSeconds invalidate]时,TimerCountSeconds崩溃.它们是这样使用的: -(id)initialize { //Gets called, when the app launches and wh 我的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一样调用方法可能会导致你的崩溃. 总结

以上是内存溢出为你收集整理的iphone – NSTimer崩溃,当我调用[Timer isValid]或[Timer invalidate]全部内容,希望文章能够帮你解决iphone – NSTimer崩溃,当我调用[Timer isValid]或[Timer invalidate]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1057693.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存