NSTimer深入研究

来源:互联网 发布:python sin函数图像 编辑:程序博客网 时间:2024/04/26 16:17
NSTimer深入研究

在使用NSTimer的时候老是出现崩溃的情况,感觉有很多地方都是使用不当的地方,所以深入研究一下。

1.什么时候该[retry_connect_timer invalidate];
苹果官方文档里面的原话if you create a repeating timer, you must invalidate it when you want it to stop firing.
不是什么时候都能用invalidate,只有当你创建了一个repeating timer的时候,你才能调用那个方法

2.那么如何关闭no repeating timer?
a.
              retry_connect_timer = [NSTimer  scheduledTimerWithTimeInterval:retryIntrval target:self selector:@selector(connect_camera) userInfo:nil repeats:NO];

b.
-(void)connect_camera
{
    retry_connect_timer = nil;

}

c.
其他函数
        if (retry_connect_timer) {
            
            [retry_connect_timer invalidate];
            retry_connect_timer = nil;
        }


“双语播放器”已在app store上架,欢迎大家前去下载(主要用于看电影,学英语,程序员一定要学好英语!)

这里是链接:

https://itunes.apple.com/cn/app/shuang-yu-bo-fang-qi-kan-dian/id950279764?mt=8