This code has a few issues. You are reloading the data in a background thread. You are reloading the table view a lot. Each time you reload the data you throw multiple exceptions.
There is a simpler approach:
NSAssert([urlArray count] > indexPath.row, @"There are more rows than image URLs");
NSInteger index = indexPath.row;
NSString *URLString = [urlArray objectAtIndex:index];
// Prep the cell to download the image
cell.imageView.tag = index; // cell needs to remember which image it's downloading.
cell.imageView.image = nil; // Remove the image from the previous use of cell.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Download the image in the background
UIImage *image = [self getImageFromURL:URLString];
dispatch_async(dispatch_get_main_queue(), 0), ^{
// Back on the main thread, set the image in the cell.
if (cell.imageView.tag == index) { // only if the cell is on the same index.
cell.imageView.image = image;
}
});
});