2010-11-02 5 views
1

J'utilise le code suivant pour aller chercher des images qui vont dans une tableview. Mais il faut un certain temps (5 à 6 secondes) pour obtenir les 30 images.Améliorer la vitesse - UIImage de NSURL

Y a-t-il une façon plus intelligente et plus rapide de faire cela?

NSString *imageUrl = ......; 
NSString *urlStr = 
[imageUrl UrlstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSString *path = [[NSString alloc] initWithFormat:@"http://xxx.dk/xml.aspx%@", urlStr]; 
NSURL *url = [NSURL URLWithString:path]; 


NSData *data = [NSData dataWithContentsOfURL:url]; 
UIImage *img = [[UIImage alloc] initWithData:data]; 
return img; 
[..... release]; 

Répondre

0

Je préfère télécharger chaque nouvelle image dans le tableau d'images lorsqu'une cellule apparaît à l'écran et afficher uniquement l'image déjà enregistrée si une cellule apparaît à l'écran pour la deuxième fois (à savoir l'image de cette cellule a été déjà téléchargé).

7

Voici profileimg est un get de api, String nom

NSString *profileimg=[Check objectForKey:@"IMAGE"]; 

imageview.image=[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:profileimg]]]; 
Questions connexes