Request main thread Refresh UI in iOS

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.