Sto sviluppando un'applicazione iOS 4 con iOS 5.0 SDK e XCode 4.2.Caricamento di un'immagine in UIImmagine in modo asincrono
Devo mostrare alcuni post blog in un UITableView. Quando avrò recuperato i tutti i dati di servizio web, io uso questo metodo per creare un UITableViewCell:
- (BlogTableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"BlogCell";
BlogTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"BlogTableViewCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[BlogTableViewCell class]])
{
cell = (BlogTableViewCell *)currentObject;
break;
}
}
}
BlogEntry* entry = [blogEntries objectAtIndex:indexPath.row];
cell.title.text = entry.title;
cell.text.text = entry.text;
cell.photo.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entry.photo]]];
return cell;
}
Ma questa linea:
cell.photo.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entry.photo]]];
è così lento (entry.photo ha un URL http).
C'è un modo per caricare quell'immagine in modo asincrono? Penso che sia difficile perché tableView: cellForRowAtIndexPath viene chiamato molto spesso.
Grazie per la risposta. Funziona!! – VansFannel
Se qualcuno ha bisogno di ridimensionare/ritagliare le funzionalità, ho integrato questa libreria con UIImage + Ridimensiona libreria. Controllalo in https://github.com/toptierlabs/ImageCacheResize – Tony
questa libreria ha problemi se si scrivono informazioni in NSTemporaryDirectory parallelamente a questo. Qualche altra soluzione? – jose920405