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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -