2013-07-09 89 views
0

我的代碼以異步方式下載後得到的圖像是是否有可能從UIImageView的圖像是使用AFNetworking

[imageView setImageWithURL:[NSURL URLWithString:@"…"]];

設置圖像。哪個工作正常。

現在我想知道如何從imageView中獲取下載的圖像。如果我做imageView.image我以佔位符圖像結束。有沒有解決方案?

+0

的NSString * IMAGEURL = @」的形象的另一種方法YourURLHere「; NSData * imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]]; imageView.image = [UIImage imageWithData:imageData]; – Hanuman

+0

你想對圖像做什麼?你可以將它作爲NSData保存到磁盤並從那裏加載。 – soryngod

回答

2

,你必須使用以下方法:

[imageView setImageWithURLRequest:request 
     placeholderImage:placeholder 
       success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
        // the downloaded image is image 
       } 
       failure:errorHandler] 
1

存在這樣的擴展類

- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 
       placeholderImage:(UIImage *)placeholderImage 
         success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 
         failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 

,讓你在成功

相關問題