Im trying to load an image from an url.
Following is my code..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@""];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
dispatch_async (dispatch_get_main_queue(), ^{
NSData * storeImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:productImageArray[indexPath.row]]];
self.productImage.image = [UIImage imageWithData:storeImageData];
});
[cell.contentView addSubview:self.productImage];
return cell;
}
The problem is that,
- UI freezes till the image is loaded.
- Only the last cell is loading the image but the remaining cells are not loading the image.
How can I sort this out?