dispatch_async(dispatch_get_main_queue(),^(){
[NSThread sleepForTimeInterval:5.0f];
NSLog(@"延迟5秒");
});
NSLog(@"顺序打印下来的”);
1、开启异步线程
dispatch_async(dispatch_get_main_queue(),^(){
//在主线程异步操作
});
2、异步延迟加载
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
<#code to be executed after a specified delay#>
});
3、同步延迟加载
[NSThread sleepForTimeInterval:5.0f];
网友评论