iphone - How to update data on the main thread after running code in the background? -


i have dispatch_queue code i'm using make 3 different data requests. i'm updating tableview on main thread. else can put in main thread? i'm using [self requestextendeddata]; download data web service parsed , set uilabels etc...

my question is: if have [self requestextendeddata]; running in background thread how update uilabels content data in main thread? should put else in main thread area? uiview, uilabels , uibutton objects etc...

thanks help

dispatch_queue_t jsonparsingqueue = dispatch_queue_create("jsonparsingqueue", null);  // execute task on queue asynchronously dispatch_async(jsonparsingqueue, ^{      [self requestuserdata]; // request user comments data     [self requestextendeddata]; // request extended listing info data     [self requestphotodata]; // request photo data       // once done, if need can call     // code on main thread (delegates, notifications, ui updates...)     dispatch_async(dispatch_get_main_queue(), ^{         [self.tableview reloaddata];       }); });  // release dispatch queue dispatch_release(jsonparsingqueue); 

this apple document saying:

note: part, uikit classes should used application’s main thread. particularly true classes derived uiresponder or involve manipulating application’s user interface in way.

that means should put uiview, uilabels , uibutton objects code in main thread this:

dispatch_async(dispatch_get_main_queue(), ^{     [self.tableview reloaddata];     // ui update code here }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -