工具---定时器

定时器的写法:

第一种:scheduled的初始化方法将以默认mode直接添加到当前的runloop中.

[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];

- (void)timerAction:(NSTimer *)sender
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

 第二种: 不用scheduled方式初始化的,需要手动addTimer:forMode: 将timer添加到一个runloop中

 NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; 
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];



- (void)timerAction:(NSTimer *)sender
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
原文地址:https://www.cnblogs.com/bachl/p/4769742.html