NSTimer使用两点注意事项

  • NSTimer在UITableViewCell中使用是,需要将timer加到runLoop中。
      countDownTimer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(countDown:) userInfo:nil repeats:YES];
      NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
      [currentRunLoop addTimer:countDownTimer forMode:NSRunLoopCommonModes];  
  • 同一个timer在重复使用之前必需invalidate, 否则会造成之前的timer无法停掉,两个timer同时存在。导致的现象就是timer同时更新两次。

blog addr:http://timbao.github.io/blog/2015/06/05/use%20NSTimer%20attention/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容