编辑:我自己找到了答案,但这里是为其他需要它的人提供的:
UIImageView 无法共享,因此每个可见单元格都需要每个 UIImageView 的不同实例化。现在你知道了。
我有一个包含两种类型单元格的自定义表格。一个单元格仅设置为在复选标记类型的普通附件之间切换。另一个单元格设置为具有自定义图像作为附件类型。选择后,附件图像将更改为其相反类型,显示“已邀请”或“邀请”消息。
我已将错误代码缩小到以下内容,在我的 tableView:cellForRowAtIndexPath 委托方法中找到。
if(indexPath.section == 0){
cell = [tableView dequeueReusableCellWithIdentifier:self.directCellID];
cellValue = [self.contactsUsingApp objectAtIndex:indexPath.row];
cell.imageView.image = [self getContactImage:indexPath.row];
//vvvvvvvvvvvvvvvvv This is the section at fault vvvvvvvvvvvvvvvvv
if([self.selectedContactsUsingApp containsObject:indexPath])
cell.accessoryView = self.invitedStatus;
else
cell.accessoryView = self.notInvitedStatus;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
如果我注释掉该部分,我将不再出现失控的内存使用情况(模拟器向我显示正在进行某种恒定分配,从 40Mb 开始后它超过了 1.29Gb),但显然,图像不再显示。
如果重要的话,UIImageViews 初始化如下:
UIImage *invite = [self imageWithImage:[UIImage imageNamed: @"invite_btn.png"] scaledToSize:CGSizeMake(40, 20)];
UIImage *invited = [self imageWithImage:[UIImage imageNamed: @"invited_btn.png"] scaledToSize:CGSizeMake(40, 20)];
self.notInvitedStatus = [[UIImageView alloc]initWithImage:invite];
self.invitedStatus = [[UIImageView alloc]initWithImage:invited];
(imageWithImage:scale 是一个函数,它将调整大小的图像返回到适当的比例,以适应此处找到的视网膜:调整 UIImage 大小的最简单方法? https://stackoverflow.com/questions/2658738/the-simplest-way-to-resize-an-uiimage)
当我选择其中一个单元格时,会发生相同的冻结,因为我的 tableView:didSelectRowAtIndexPath 方法通过与初始化方法相同的切换逻辑工作。
Help?