2013-08-17 74 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); 
     } 
} 
相關問題