Slow loading the images from URL in UITAbleView.

后端 未结 9 686

I\'m loading the images from URL in UITableView. But it\'s very slow when loading an view. Here\'s an example,

UIImage *image = nil;
image = [UIImage imageW         


        
9条回答
  •  时光说笑
    2020-12-20 10:13

    //Make use of dispatch queue for faster processing of data. add this in viewDidLoad

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        NSData * data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
        [self performSelectorOnMainThread:@selector(setImage:) withObject:data waitUntilDone:YES];
    });
    

    //once data is got set the image and reload tableview

    -(void)setImage:(NSData *)responseData
    {
    image = [UIImage imageWithData:responseData];
    [tableView reloadData];
    }
    

提交回复
热议问题