ios - Using blocks to download image, freezing UI -
in app downloading image using blocks freezing ui. have 1 network class contains method download image,
-(void)downloadimagewithcompletionhandler:^(nsdata *adata, nserror *error)ablock; i calling above method in view controller download image. once image downloaded using nsdata show in image view. network class method uses nsurlconnection methods download image.
   [[nsurlconnection alloc] initwithrequest:theurlrequest delegate:self]; once data download complete calling completion handler block of view controller.
but not sure why ui freezing? can me find doing wrong?
thanks in advance!
- (void) setthumbnailurlstring:(nsstring *)urlstring {     nsstring *url= [nsstring stringwithformat:@"%@",urlstring];     //set request:     nsmutableurlrequest *request = [[nsmutableurlrequest alloc]init];     [request seturl:[nsurl urlwithstring:url]];      nsoperationqueue *queue=[[nsoperationqueue alloc] init];     if ( queue == nil ){         queue = [[nsoperationqueue alloc] init];     }     [nsurlconnection sendasynchronousrequest:request queue:queue completionhandler:^(nsurlresponse * resp, nsdata     *data, nserror *error)      {          dispatch_async(dispatch_get_main_queue(),^                         {                             if ( error == nil && data )                             {                                 uiimage *urlimage = [[uiimage alloc] initwithdata:data];                                 _headimageview.image=urlimage;                                 _backgroundimageview.image=urlimage;                             }                         });      }]; } 
Comments
Post a Comment