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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -