NSTimer

注意事项:NSTimer是一次性的,要么持续工作,一旦停止工作就无法再次使用

    // 返回一个自动开启任务的定时器

    self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(nextPage:) userInfo:@"123" repeats:YES];

    

    // NSDefaultRunLoopMode(默认) : 同一时间只能处理一个任务

    // NSRunLoopCommonModes(公用) : 可以分配一定的时间处理其他任务

    

    // 作用:修改timer在runloop中的模式为NSRunLoopCommonModes.

    // 目的:不管主线程在做什么操作都会分配一定的时间处理timer

    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
原文地址:https://www.cnblogs.com/wwjwb/p/12650726.html