Desidero impostare le immagini di celle tableview in una delle mie app. Io uso AFNetworking (1.2.1)
e lo faccio con setImageWithURLRequest
.AFNetworing - setImageWithURLRequest non funziona
Il mio codice in cui ho impostato immagini assomiglia a questo:
if (user.avatar) {
NSString *imageUrl = user.avatar.url;
[cell.profileImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[cell setNeedsLayout];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
mio errore restituisce log questo:
Error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1f5b56a0 {NSErrorFailingURLKey=https://d2rfichhc2fb9n.cloudfront.net/image/5/Cf7T_BA6- NFGL5ah0w4hdvmk_Vp7InMiOiJzMyIsImIiOiJhZG4tdXNlci1hc3NldHMiLCJrIjoiYXNzZXRzL3VzZXIvZTIvM2MvMjA vZTIzYzIwMDAwMDAwMDAwMC5qcGciLCJvIjoiIn0}
E le immagini dosn't da impostare. Non ho avuto questo problema prima di essere aggiornato a AFNetworking (1.2.1)
. Qualche idea?
Aggiornamento
Ho cercato di togliere gli spazi dal URL come questo:
NSString *imageUrl = [user.avatar.url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Ma ottengo lo stesso errore. E potrebbe essere pericoloso se l'API a volte conterrebbe un nome file immagine che contiene spazi bianchi.
Grazie, ha funzionato! Spostato su 'tableView: cellForRowAtIndexPath'. – Anders
la tua risposta mi ha salvato la giornata .... Grazie .... – Manoj
Questo codice crea il ciclo di conservazione ?? Sono sicuro che il blocco manterrà la cella, ma la cella mantiene il blocco ???? –