Only the main thread in iOS can immediately refresh the UI. If you are listening for asynchronous messages, triggering a callback function, or calling an asynchronous method, requesting that the UI be refreshed creates a problem with thread blocking and latency.
Can be [OBJC] view plain copy if ([Nsthread ismainthread]) { [self.downloadmapbtn setimage:[uiimage imagenamed:@ "Download_map.png"] forState:UIControlStateNormal]; [self.downloadMapBtn setneedsdisplay]; } else { dispatch_sync ( Dispatch_get_main_queue (), ^{ //update ui in UI thread here [ self.downloadmapbtn setimage:[uiimage imagenamed:@ "Download_map.png"] forState: uicontrolstatenormal]; [self.downloadMapBtn setneedsdisplay]; }); }
This method is used to send messages to the main thread and to refresh.
Related reading
Http://www.ios-developer.net/iphone-ipad-programmer/development/threads/updating-ui-controls-on-background-threads
Http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial