簡體   English   中英

使用SDWebImage下載大圖像時應用崩潰

[英]App crash while downloading large images using SDWebImage

我正在使用SDWebImage從服務器異步下載圖像。服務器上的某些圖像大小為1772x1476像素。我正在UICollectionView上顯示這些圖像。 多次運行后,我收到內存警告和應用程序崩潰。有時是在第一次下載圖像時發生的,有時是在我上下滾動集合視圖時發生的。 這是我的代碼-

我在我的x代碼上收到警告,如下圖

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

[Mainimage sd_setImageWithURL:[NSURL URLWithString: Obj.imageYH] placeholderImage:[UIImage imageNamed:@""]];

   return cell;
}

在此處輸入圖片說明

您可以使用 :

[SDImageCache sharedImageCache] .config.shouldDecompressImages = NO; [[SDWebImageDownloader sharedDownloader] setShouldDecompressImages:NO];

在4.0-beta版本中

如果您的應用程序不需要顯示完整尺寸的圖像,則將其縮小並顯示始終是一個好習慣。 這是做什么的例子。

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:url delegate:self options:0 success:^(UIImage *image) 
{
    //Scale down the image here and then set to your view.
}

它應該可以幫助您減少內存問題。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

            UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

    [Mainimage setImageWithURL:[NSURL URLWithString: Obj.imageYH] placeholderImage:[UIImage imageNamed:@""]];

           return cell; 
}        

嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM