2014-03-31 38 views
2

我在我的應用程序中使用AFNetworking來下載圖像的代碼和細節。我將所有這些NSStrings存儲在一個NSObject中的那些對象中,存儲在NSMutableArray中。我使用NSMutableArray異步獲取圖像SDWebImage,但在下載了一些圖像後,我的應用程序崩潰了Received memory warning我嘗試過在AFNetworking中使用相同的方法,但沒有任何反應。我在兩個庫都使用這種方法。如何使用SDWebImage或AFNetworking在一個巨大的CollectionView中緩存磁盤上的圖像?

[self.pictureImg setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:kDefaultLoadingImage]]; 

我想知道如何cache在磁盤上以及如何清除緩存,每當我需要它的圖像。我不在乎你是否使用AFNetworkingSDWebImage。我在我的自定義cells中使用該方法。

謝謝!

回答

0

只需使用此FastImageChache庫。它可以將圖像緩存在你想要的磁盤上。

0

調用此方法時,你 「接收到內存警告」

[SDWebImageManager.sharedManager.imageCache clearMemory]

+0

它不起作用.. – croigsalvador

0

嘗試此,

SDImageCache * imageCache = [SDImageCache sharedImageCache];

[imageCache clearMemory];

0

對於這種方法,AFNetworking自己能夠處理高速緩存,除非你不忽略的NSURLRequest

0
[self.profileImage setImageWithURL:[NSURL URLWithString:urlString] 
        placeholderImage:[UIImage imageNamed:@"img_default"] 
          options:SDWebImageProgressiveDownload]; 
0

的緩存性能試試這個!使用__weak爲你的在AFTNetworking

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
    NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:20 * 1024 * 1024  // 10MB. memory cache 
                 diskCapacity:100 * 1024 * 1024  // 50MB. on disk cache 
                  diskPath:nil]; 
    sessionConfiguration.URLCache = cache; 
    sessionConfiguration.requestCachePolicy = NSURLRequestUseProtocolCachePolicy; 

在的CollectionView:cellForItemAtIndexPath:

__weak YOUR_CUSTOM_CELL *cell = (YOUR_CUSTOM_CELL *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 
NSURLRequest *requestL = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [your_model.url_image stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]; 
[your_cell.your_image_view setImageWithURLRequest:requestL placeholderImage:[UIImage imageNamed:@"test"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
    your_cell.your_image_view.image = image; 
} failure:nil]; 

我希望這將有助於!

相關問題