NStimer有可能被delay,每次间隔的时间是不一定一样(线程堵塞),如用alloc创建,需要加入runLoop中
@autoreleasepool {
NSTimer *timer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:1] interval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:1];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3]];
}
注:NSRunLoop是IOS消息机制的处理模式,NSRunLoop用来控制线程的执行和休眠
567

被折叠的 条评论
为什么被折叠?



