I am using async to get my images from an xml. Parser is working correctly and I can output the URLs. In the async I am trying to cache the images to a mutable dictionary. I am stuck in a loop and the images will not output at all any more. Here is my code that I am stuck on.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Got Here");
static NSString *CellIdentifier = @"NewsCell";
NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSLog(@"Got Here 2");
// Configure the cell...
NewsItem *item = [newsItemsArray objectAtIndex:indexPath.row];
cell.newsTitle.text = item.title;
NSLog(@"Got Here 3");
NSMutableDictionary *record = [_records objectAtIndex:[indexPath row]];
if ([record valueForKey:@"actualImage"]) {
NSLog(@"Record Found");
[cell.newsImage setImage:[record valueForKey:@"actualImage"]];
} else {
NSLog(@"Record Not Found");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,(unsigned long)NULL), ^(void)
{
NSLog(item.image);
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:item.image]];
dispatch_async(dispatch_get_main_queue(), ^(void){
[record setValue:[UIImage imageWithData:imageData] forKey:@"actualImage"];
[cell.newsImage setImage:[record valueForKey:@"actualImage"]];
if (tableView) {
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
});
});
}
return cell;
}
Thanks in advance for you help.