1

我有问题,需要帮助。我有一张桌子,在单元格上我有图像的水平滚动。图片是从网上下载的。当我下载第 6 张图片时,我的应用程序崩溃了。对于异步上传,我使用https://github.com/rs/SDWebImage

  -(void) fastCreateImage
   {
int tempID = self.currentPageNow;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.2f * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
    if(tempID==self.currentPageNow)
    {
        NSUInteger objIdx = [self.imageViews indexOfObject: [NSNumber numberWithInt:tempID]];
        if(objIdx != NSNotFound) {
            NSLog(@"WAS CACHED!!!!!!");
        }
        else
        {
             UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 193.5f)];

    NSString *urlInString =[NSString stringWithFormat:@"%@/uploads/gallery/hotels/%@",webSite,[self.urlGarbage objectAtIndex:self.currentPageNow]];
            SDWebImageManager *manager = [SDWebImageManager sharedManager];
            [manager downloadWithURL:[NSURL URLWithString:urlInString]
                            delegate:self
                             options:0
                             success:^(UIImage *image, BOOL cached)
             {
                 myImageView.image = image;
                 [[self.views objectAtIndex:tempID] addSubview:myImageView];
                 [self.imageViews addObject:[NSNumber numberWithInt:tempID]];
                 NSLog(@"LOADED IMG");
             }
                             failure:nil];
            [myImageView release];
        }


    }
});
 }
4

1 回答 1

0

由于您收到内存警告,我猜您的图像太大而无法放入内存。图像最多使用width*height*4(取决于颜色深度)您的内存。计算每个图像的内存需求,看看这是否是问题所在。

于 2012-10-10T09:38:23.703 回答