Ich Bilder für meine uitableview asynchron mit GCD herunterladen, aber es gibt ein Problem - beim Bildlauf flackern und ändern die ganze Zeit. Ich habe versucht, Bild mit jeder Zelle auf Null zu setzen, aber es hilft nicht viel. Beim schnellen Zurückscrollen sind alle Bilder falsch. Was kann ich dagegen tun? Hier ist meine Methode für Zellen:Asynchrones Herunterladen von Bildern für UITableView mit GCD
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (self.loader.parsedData[indexPath.row] != nil)
{
cell.imageView.image = nil;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[self.loader.parsedData[indexPath.row] objectForKey:@"imageLR"]]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = image;
[cell setNeedsLayout];
});
});
cell.textLabel.text = [self.loader.parsedData[indexPath.row] objectForKey:@"id"];
}
return cell;
}
@SeamusCampbell, konnte nicht 'indexPath.row' das gleiche gilt für die wiederverwendet Zelle sein, wenn es in einem anderen Abschnitt ist? In diesem Fall würde der Tag-Check unpassend verlaufen. –
Ja, der obige Code geht von einer einteiligen Tabelle aus. –
@SeamusCampbell, irgendwelche Gedanken für eine Multi-Section-Tabelle :) –