工具---定时器

定时器的写法:

第一种: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];
}

 

posted @ 2015-08-29 20:40  百川hl  阅读(120)  评论(0编辑  收藏  举报