列举iOS开发中,几种延迟执行的方法:
1. GCD方法:(可设置在主线程还是子线程执行)
2. performSelector方法:(必须在主线程)dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ //do something... });
[self performSelector:@selector(method) withObject:nil afterDelay:1.0f];
3. sleep方法:(主线程、子线程均可,阻塞式执行方式)
[NSThread sleepForTimeInterval:1.0f]; //do something...
4. 定时器,NSTimer方法:(必须在主线程)
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(method) userInfo:nil repeats:NO];