2014-06-15 16 views
7

Sto sviluppando un'applicazione iOS e sto utilizzando SDWebImage come API di downloader di immagini.SDWebImage non mostra un'immagine sebbene l'immagine esista da remoto sul server

sto usando un UICollectionView e lo faccio nel metodo

- (UICollectionViewCell *)collectionView:(SMToplinksCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

Alcune immagini vengono scaricate, e alcuni non lo sono. Quelli che non hanno scaricato mostra il messaggio di errore:

2014-06-15 12:11:50.203 c_shadow_ios_iphone[6867:60b] ===Error:Error Domain=NSURLErrorDomain Code=-1100 "The operation couldn’t be completed. (NSURLErrorDomain error -1100.)"

Errore -1100: NSURLErrorFileDoesNotExist

Inoltre, l'UIImage sembra essere pari a zero.

Ho controllato l'URL che SDWebImage tenta di scaricare e mi viene l'immagine correttamente, quindi l'errore non sembra ragionevole

ecco il codice metodo che uso:

- (UICollectionViewCell *)collectionView:(SMToplinksCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{  
SMToplinkCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:TopLinksCollectionViewID forIndexPath:indexPath]; 

NSArray *collectionViewArray = [self getToplinksArrayAccordingToTheIndex:collectionView.index]; 

// CONFIGURE THE CELL 
SMTopLinksObject *dataObject = collectionViewArray[indexPath.item]; 

// 1. Set the toplink title 
cell.title  = dataObject.name; 

// 2. Get the default image and blur it 
cell.imageName = dataObject.localImageName; 

// 3. Activate the preloader that shows the loading status 

// 4. Load the image from the server 
SDWebImageManager *manager = [SDWebImageManager sharedManager]; 
NSString *toplinksGetRequest = dataObject.prepareToplinksGetRequest; 
NSURL *toplinksURL = [NSURL URLWithString:toplinksGetRequest]; 

NSLog(@"=== Trying to download image from URL:%@", toplinksGetRequest); 
[manager downloadWithURL:toplinksURL 
       options:0 
       progress:^(NSInteger receivedSize, NSInteger expectedSize){ 
        //progression tracking code       
       } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished){ 
        if(finished) 
        { 
         NSLog(@"===image finished loading, image:%@", image); 
         NSLog(@"===Error:%@", error); 
        } 
        if (image) 
        { cell.shadowPageImageView.image = image; } 
}];  
NSLog(@"=========Cell:%@", cell); 
return cell; 
} 

uscita

image is NIL

Error: Error Domain=NSURLErrorDomain Code=-1100 "The operation couldn’t be completed. (NSURLErrorDomain error -1100.)"

Cosa mi manca qui?

+0

Hai usato UIImageView + AFNetworking per le immagini? – Nirav

+0

Ho usato UIImageView + WebCache.h come suggerito in SDWebImage ReadMe – raven99

+1

Risolvi? Ho il problema simile. ty – George

risposta

0

Prova con seguente codice

Importa la categoria di ImageView #import <SDWebImage/UIImageView+WebCache.h> che è già in SDWebImage

Poi, nel tuo cellulare per cellForItemAtIndexPath

[cell.imgVwUser sd_setImageWithURL:[NSURL URLWithString:objPhoto.imageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
    DLogs(@"completed"); 

    [cell.loadIndicator stopAnimating]; 

}]; 
4
[cell.diviceIV sd_setImageWithURL:[NSURL URLWithString:imgStringUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
    if (image){ 
     // Set your image over here 
     }else{ 
      //something went wrong 
     } 

}]; 

Il punto principale è opzioni: Opzione SDWebImageRetryFailed che devi dare nel tuo metodo. Funziona per me puoi provarlo.

+0

Questa "funzionalità" (failedURLs) è fondamentalmente un bug incorporato direttamente in SDWebImage. Consiglierei di dare un'occhiata a quadri alternativi (ce ne sono molti). – kean

3

Ho avuto lo stesso problema. I got "Errore Domain = SDWebImageErrorDomain Code = -1" Tentativo di caricare un url nil ", ma l'immagine è presente in quell'URL particolare Ho trovato che l'errore si verifica per immagini a bassa risoluzione Per immagini di qualità migliore, il caricamento avviene pozzo. Controllare lo stesso codice per ottenere immagini migliori risoluzione.

0

ho incontrato lo stesso problema. ho provato tutto il modo di cui sopra, ma non potrebbe funzionare bene.

Infine ho scoperto il motivo è la nome dell'URL dell'immagine. Penso che IOS non supporti il ​​nome cinese dell'URL dell'immagine, quindi dovresti codificare l'URL.

Esempio:

url = [_img_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
0

For me the issue was very low resolution images. For high resolution images this works perfectly!!!!

0

Usa come questo

self.imgUserProfile.sd_setImage(with: imageUrl, placeholderImage: UIImage(named: "profile_placeholder"), options: SDWebImageOptions.refreshCached, progress: nil, completed: { (image, error, cache, url) in 
     if error == nil { 
      self.imgUserProfile.image = image 
     } 
    })