2013-01-03 12 views
7

mio scopo sta cercando di ottenere la dimensione dell'immagine scaricata tramite il blocco di successo come di seguito:ottenere [NSURL cachePolicy]: selettore non riconosciuto inviato ad esempio durante il download di un'immagine, AFNetworking

[imageView setImageWithURLRequest:[NSURL URLWithString:((ObjectA*)obj[indexPath.row]).imageUrl] 
       placeholderImage:nil 
         success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
          CGFloat imageHeight = image.size.height; 
          CGFloat imageWidth = image.size.width; 
          NSLog(@"width of image is %f",imageWidth); 
          NSLog(@"height of image is %f",imageHeight); 
         } 
         failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 
          ; 
         } ]; 

Tuttavia, sono ottenendo un arresto anomalo con errore visualizzato come di seguito:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL cachePolicy]: unrecognized selector sent to instance 0x1edb9e70' 

Qualcuno conosce il motivo di questo errore. Per favore, aiuto se hai qualche idea

+0

Un po 'di eseguire il debug? Sono abbastanza sicuro che non sia l'oggetto che pensi sia. –

+1

'[NSURL cachePolicy]' Da dove viene chiamato? –

risposta

15

L'errore ti sta dicendo che cachePolicy (che è un metodo NSURLRequest) viene chiamato su un oggetto NSURL.

Il problema è che si passa un oggetto NSURL come primo parametro anziché un oggetto NSURLRequest. (Io non sono familiarità con questo terzo API partito, ma la documentazione sembra essere here)

12

problema è con questo codice:

[imageView setImageWithURLRequest:[NSURL URLWithString:((ObjectA*)obj[indexPath.row]).imageUrl] 

Il parametro di setImageWithURLRequest: è NSURLRequest, si sta passando NSURL. Ecco perché si sta bloccando.

modificarla in:

[imageViewsetImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:((ObjectA*)obj[indexPath.row]).imageUrl]] 
+0

hanno ancora problemi? –

2

Credo che il problema è nella prima linea

[imageView setImageWithURLRequest:[NSURL URLWithString:imageUrl] 

setImageWithURLRequest dalla firma sembra in attesa di un "URLRequest", mentre si passa un URL.

Quindi creare un URLRequest con la URL e passare e vedere se si sta lavorando

Problemi correlati