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,
- updating label text.
- set image on imageview.
- 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
Post a Comment