NSTimer时应注意避免的坑

title: NSTimer

tags:

  1. NSTimer不生效:非主线程中代码中会遇到
    在我们进行多线程编程时,所有的Source都需要添加到Runloop中才能生效,对于我们的NSTimer当然也需要添加到Runloop中才能生效。如果一个Runloop中没有任何Source的话,会立即退出的。而主线程的Runloop在程序运行时,系统就已经为我们添加了很多Source到Runloop中,所以主线程的Runloop是一直存在。

  2. timer = [NSTimer scheduledTimerWithTimeInterval:0.1 // 10ms

      target:self
    selector:@selector(loop:)
    userInfo:nil
     repeats:YES];
    
Contents
  1. 1. tags:
,