在开发过程中经常会用到:几秒后 执行某个方法
1、NSRunLoop
[self performSelector:@selector(laterExecute) withObject:nil afterDelay:5.0f];
2、定时器
[NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(laterExecute) userInfo:nil repeats:NO];
3、GCD
double delayInSeconds = 5.0;
__block ViewController *selfBlcok = self;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
[selfBlcok laterExecute];
});
网友评论