ios - Method Delay In NSURLSession Block -


when call block:

nsurlsession *session = [nsurlsession sharedsession];     [[session datataskwithurl:url             completionhandler:^(nsdata *data,                                 nsurlresponse *response,                                 nserror *error) {                   _data = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:nil];                  _label.text = [nsstring stringwithformat:@"%@°",([[[self.data objectforkey:@"main"] objectforkey:@"temp"] floatvalue]) - 273.15)];              nslog(@"%@",self.data);               }] resume]; 

the code inside block takes long time execute, though nslog gets called - what's going on? i've tried sorts of solutions, nothing working.

always perform ui update related task on main thread otherwise take time perform ui.

like,

  1. updating label text.
  2. set image on imageview.
  3. timer related operation.

so use below code

dispatch_async(dispatch_get_main_queue(), ^{             _label.text = [nsstring stringwithformat:@"%@°",([[[self.data objectforkey:@"main"] objectforkey:@"temp"] floatvalue]) - 273.15)]; } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -