【问题标题】:Application crashes while using SDWebImageCache in IOS 9 in tableview在表视图中使用 IOS 9 中的 SDWebImageCache 时应用程序崩溃
【发布时间】:2015-11-16 08:07:31
【问题描述】:

我正在使用 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

请帮助我摆脱这种情况。压力很大……

【问题讨论】:

    标签: objective-c ios8 afnetworking ios9 sdwebimage


    【解决方案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"]];
    

    【讨论】:

    • 请添加更多描述和/或有关您的答案以及它如何解决所问问题的信息,以便其他人可以轻松理解它而无需要求澄清
    • 例如,您想要 tableview 单元格中的所有图像,因此首先获取 nsmutablearray 中的所有图像,然后使用 NSString 和 key 值并给出使用 ObjectAtIndex 路径,如: NSString *Banner = [NSString stringWithFormat: @"%@",[[imagedata valueForKey:@""]]objectAtIndex:indexpath.row]; NSLog(@"%@",横幅);在那一行之后粘贴字符串 [cell.imgMain sd_setImageWithURL:[NSURL URLWithString:Banner] placeholderImage:[UIImage imageNamed:@"placehoder2.jpg"]];
    • 请编辑您的答案并在此处提供信息,以便其他寻求答案的人更容易看到
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        使用这个

        将代码添加到 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];
        
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-12-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-01-26
          • 1970-01-01
          • 2021-09-29
          相关资源
          最近更新 更多