gpt4 book ai didi

ios - 大图像崩溃 UITableView 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:55 25 4
gpt4 key购买 nike

所以我一直在寻找这个问题的答案,但仍然无法弄清楚。我有一个包含 15 个图像的数组,所以我尝试使用 UITableViewCell 中的 subview 进行显示。下面的代码——我读过的所有内容都提到使用自动释放/释放来解决问题,但我在尝试这样做时只是遇到了 ARC 错误。任何帮助将不胜感激。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
int countthis = indexPath.row;
NSString *image = imgarr[countthis];
UIImageView *iv = [[UIImageView alloc] initWithFrame:(CGRect){.size={320, tableView.rowHeight}}];
iv.image = [UIImage imageNamed:image];
cell.imageView.image = iv.image;
return cell;
}

最佳答案

无论您的域是什么,大文件往往会导致问题。具体来说,Apple 表示:

You should avoid creating UIImage objects that are greater than 1024 x 1024 in size.

看起来您正在尝试调整图像的大小,但 UIImages 是不可变的。因此,您分配的 UIImageView 只会浪费处理器周期。

如果您遇到需要缩小的大图像,请考虑在将它们分配给单元格之前进行缩放。您可能会发现这些例程很有用:The simplest way to resize an UIImage?

Re autorelease/release:这些自 ARC 以来已被弃用。您的代码似乎没有泄漏内存。我不会出汗。但是您应该编辑您的问题以包含有关崩溃的详细信息。

关于ios - 大图像崩溃 UITableView 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18907132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com