OGeek|极客世界-中国程序员成长平台

标题: 从 URL 显示大尺寸图像时,iOS 应用程序崩溃 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 16:57
标题: 从 URL 显示大尺寸图像时,iOS 应用程序崩溃

我尝试了以下用于图像缓存的库:

但应用在滚动时仍收到内存警告、崩溃和卡住

我使用 UITableViewCell 来显示图像。

部分图片为 1.5 MB 或更大,所以我不确定这是问题所在还是其他问题?

请指导。 您的任何努力将不胜感激。

编辑:

我有 UITableViewCell 用于在 UITableView 中加载 UICollectionViewCell:

UITableViewCell 的代码。

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"homecell";

    HomeViewCell *cell = (HomeViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed"HomeViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    NSArray *arr=[[arrPsots objectAtIndex:indexPath.row ] valueForKey"ostImage"];
    [cell setCollectionWithImageArray:arr];

    return cell;
}

UICollectionViewCell 的代码。

- (UICollectionViewCell *)collectionViewUICollectionView *)collectionView1 cellForItemAtIndexPathNSIndexPath *)indexPath{

    static NSString *cellIdentifier = @"ScrollCollectionCell";
    ScrollCollectionCell *cell = [collectionView1 dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    NSString *imgKey = (IS_IPAD?@"ostImage""ostImage");
    NSString *strImage=[NSString stringWithFormat"%@",[arrImages valueForKey:imgKey]];

    [cell.imgScroll setImageWithURL:[NSURL URLWithString:strImage] placeholderImage:[UIImage imageNamed"placeholder.png"]];

    if ([arrImages count]==1) {

        self.pageControllPostImg.hidden=TRUE;
    }
    self.pageControllPostImg.hidden=TRUE;
    self.pageControllPostImg.numberOfPages=[arrImages count];
    return cell;
}



Best Answer-推荐答案


我在一个项目中遇到过这个问题,以前的程序员每次都创建新单元格并且没有使用可重复使用的单元格。

关于从 URL 显示大尺寸图像时,iOS 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38310208/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4