在tableview中使用IOS 9中的SDWebImageCache时,应用程序崩溃

时间:2015-11-16 08:07:32

标签: objective-c ios8 afnetworking ios9 sdwebimage

我正在使用SDWebImageCache在UITableview自定义单元格中加载缩略图。但是在ios 9中,当我滚动UITable时应用程序崩溃了。类似于AFNetworking(UIIMageView + AFNetworking)类。

我在SDWebImageCache中使用的类是:

[cell.imgMain sd_setImageWithURL:imageLoadUrl
                    placeholderImage:[UIImage imageNamed:@"*placeholder image*"]
                             options:SDWebImageRefreshCached];

我在UIIMageView + AFNetworking中使用的课程是:

        [cell.imgMain setImageWithURLRequest:[NSURLRequest requestWithURL:imageUrl]
                     placeholderImage:[UIImage imageNamed:@"wachizLogoIcon.png"]
                              success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

                                  cell.imgMain.image=image;
                              }
                              failure:nil];

但仍然应用程序崩溃并显示以下屏幕:

APPLICATION CRASHES IN IOS 9 and sometimes for IOS 8.4

请帮助我解决这个问题。压力很大......

4 个答案:

答案 0 :(得分:1)

use this code

NSMutableArray *Imagedata;

 - 

NSString *Banner = [NSString stringWithFormat:@"%@",[[imagedata valueForKey:@""]]objectAtIndex:indexpath.row];
 NSLog(@"%@",Banner); 
[cell.imgMain sd_setImageWithURL:[NSURL URLWithString:Banner] placeholderImage:[UIImage imageNamed:@"placehoder2.jpg"]];

答案 1 :(得分:0)

我曾经遇到过类似的问题。当SDWebImageCache尝试缓存图像时,它基本上是一个低内存崩溃。尝试实现didReceiveMemoryWarning方法来调试它。在低内存上重置缓存。还要为图像设置maxCacheSize。 这些方法对我来说效果不佳,所以我切换到Haneke。我仍然需要将diskCapacity设置为某个限制。

答案 2 :(得分:0)

当您缓存图像时,它将存储在您的设备RAM中...请在调试器中检查您的RAM ...如果您缓存大量图像,这将因内存警告而终止应用程序。

答案 3 :(得分:0)

使用此

将代码添加到Appdelegate

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    NSLog(@"Clearing cache-------------");


[[SDImageCache sharedImageCache] clearMemory];
[[SDImageCache sharedImageCache] cleanDisk];
[[SDImageCache sharedImageCache] clearDisk];
[[SDImageCache sharedImageCache] setValue:nil forKey:@"memCache"];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"cache cleared"
                                                    message:Nil
                                                   delegate:Nil
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:nil];
    [alert show];

}