UITableCell AccessoryView:设置accessoryView等于UIImageView无限循环 [英] UITableCell AccessoryView: Setting accessoryView equal to UIImageView infinite loop

查看:246
本文介绍了UITableCell AccessoryView:设置accessoryView等于UIImageView无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我已经找到了我自己的答案,但这里是其他需要它的人:
UIImageViews无法共享,因此每个可见单元格需要不同的每个UIImageView实例化。现在你知道了。

我有一个自定义表,有两种类型的单元格。一个单元格设置为在类型复选标记的普通附件之间切换。另一个单元格设置为具有自定义图像作为附件类型。当选择附件图像变为其相反类型时,显示邀请或邀请消息。

I have a custom table that has 2 types of cells. One cell is just set to toggle between a normal accessory of type checkmark. Another cell is set to have a custom image as the accessory type. When selected that accessory image changes to its opposite type, showing an "Invited" or "Invite" message.

我已将故障代码缩小到以下内容,在我的tableView:cellForRowAtIndexPath委托方法中找到。

I've narrowed down the code at fault to the following, found within my tableView:cellForRowAtIndexPath delegate method.

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)但显然,图像不再显示。

If I comment out that section I no longer have runaway memory usage (the Simulator showed me that there was some sort of constant allocation going on, it got up passed 1.29Gb after starting from 40Mb) but, obviously, the images no longer show.

如果重要,UIImageViews初始化如下:

If it matters the UIImageViews are initialized as follows:

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大小的最简单方法?

(imageWithImage:scale is a function that returns a resized image to the appropriate scale accounting for retina found here: The simplest way to resize an UIImage?)

当我选择其中一个单元格时会发生同样的冻结,因为我的tableView:didSelectRowAtIndexPath方法与初始化方法使用相同的切换逻辑。

The same freezing happens when I select one of the cells because my tableView:didSelectRowAtIndexPath method works by the same toggling logic as the initialization method.

帮助?

推荐答案

我已经找到了自己的答案,但这里是为了其他人谁需要它:UIImageViews无法共享,因此每个可见单元格需要每个UIImageView的不同实例。现在你知道了。

这篇关于UITableCell AccessoryView:设置accessoryView等于UIImageView无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆