//1.通过NStimer
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(timerClick) userInfo:nil repeats:NO];
[timer setFireDate:[NSDate distantPast]];//运行
//2.通过performSelector
[self performSelector:@selector(timerClick) withObject:nil afterDelay:5.0f];
//[NSObject cancelPreviousPerformRequestsWithTarget:self];//取消延迟加载
// 3.gcd
dispatch_time_t gcdTimer = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC));
// dispatch_after:在指定时间追加处理到dispatch_queue
dispatch_after(gcdTimer, dispatch_get_main_queue(), ^{
[self timerClick];
});
// 4.使用NSThread
[NSThread sleepForTimeInterval:5.0f];
网友评论