-[UILabel setText:] must be used from main thread only
解决方法:
[self performSelectorOnMainThread:@selector(<#selector#>:) withObject:<#你要处理的数据#> waitUntilDone:YES];
- (void)<#selector#>:(<#你要处理的数据#> *)<#name#>
{
}
[self performSelector:action withObject:obj afterDelay:0.3];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 处理耗时操作的代码块...
// 通知主线程刷新
dispatch_async(dispatch_get_main_queue(), ^{
//回调或者说是通知主线程刷新,
});
});
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
XPFLog(@"任务一:");
});
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
XPFLog(@"任务二:");
});
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
XPFLog(@"任务三:");
dispatch_semaphore_signal(sem);
});
网友评论