2013-08-17 75 views
-1

我有一些在主线程上运行的代码,以及正在处理一些数据的辅助GCD线程。数据处理完毕后,我需要更新UI,最好尽快更新,那么我是否可以将它移动到主线程以便立即处理?谢谢!如何使用GCD立即在主线程上执行某些操作?

+1

你试过了什么?在网上很容易找到答案并不困难。 http://stackoverflow.com/questions/7905192/iphone-grand-central-dispatch-main-thread – CRDave

+1

http://stackoverflow.com/questions/12933397/sending-messages-from-background-thread-to-main- thread-on-ios – CRDave

+1

http://stackoverflow.com/questions/13502242/ios-how-to-get-background-thread-to-redraw-view-on-main-thread – CRDave

回答

0
void es_dispatch_sync_on_main_thread(dispatch_block_t block) 
{ 
     if ([NSThread isMainThread]) { 
       block(); 
     } else { 
       dispatch_sync(dispatch_get_main_queue(), block); 
     } 
} 
相关问题