定时器

**定时器的 创建

**  注意:自己新开线程的时候的 才可以用 --  NSRunLoop     已经在主线程的 时候 不用runLoop  不然定时器的方法 不能改UI   

       dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            timer = [NSTimer scheduledTimerWithTimeInterval:KTimeInterval target:self selector:@selector(update:) userInfo:nil            repeats:YES];

            [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

            [[NSRunLoop currentRunLoop] run];

        });

**定时器的 移除

    [timer invalidate];

    timer  = nil;

   

原文地址:https://www.cnblogs.com/zhaozhongpeng/p/4977432.html