您的位置:首页 > 其它

NStimer禁忌

2015-10-08 09:43 239 查看
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用来控制线程的执行和休眠
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: