Ios 如何禁用特定UITableViewCell的图像?

Ios 如何禁用特定UITableViewCell的图像?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在我的UITableView中,如果一个节有0行,我会告诉它这样设置: if (top3ArrayForSection.count-1 < 1) { // title of the item cell.textLabel.text = @"No items found, but we'll keep a lookout for you!"; cell.textLabel.font = [UIFont systemFontOfSize:12]

在我的
UITableView
中,如果一个节有0行,我会告诉它这样设置:

if (top3ArrayForSection.count-1 < 1) {

        // title of the item
        cell.textLabel.text = @"No items found, but we'll keep a lookout for you!";
        cell.textLabel.font = [UIFont systemFontOfSize:12];

        cell.detailTextLabel.text = [NSString stringWithFormat:@""];
        [cell.imageView setImage:[UIImage imageNamed:@""]];

}
if(top3ArrayForSection.count-1<1){
//项目名称
cell.textlab.text=@“未找到任何项目,但我们会密切关注您!”;
cell.textLabel.font=[UIFont systemFontOfSize:12];
cell.detailTextLabel.text=[NSString stringWithFormat:@”“];
[cell.imageView setImage:[UIImage ImageName:@”“];
}
这使得
detailtextlab
为空,并且
单元格.imageView
不显示。然而,细胞最终显示如下图所示。图像是空白的,但仍然占用空间,导致
textlab
像这样被推到右侧。如何删除该特定单元格的所有图像


我将使用UITableViewCell的另一个子类来显示没有图像的子类。这比尝试动态移动要容易得多。

要继续@Almo的帖子:

创建自定义表视图的第二个变体(您可以将其作为自定义表视图类的子类;这样您就不必重复代码。在子类中,跳过图像并将标签移到上面


另一种方法是使用自动布局和约束。您可以使标签的左边缘链接到图像视图的右边缘,并将标签的右边缘固定到单元格的边缘。然后,当图像视图为零宽度时,标签将移动。问题在于填充。您仍然可以从图像视图的两侧获得填充图像视图,除非在图像为空时添加自定义代码以消除图像视图上的左边缘填充。

我已经在使用子类
UITableViewCell
,我如何告诉它不包含图像?没有理由创建另一个子类。只需设置
cell.imageView.image=nil;
。只需调用
cell.imageView.image=nil;
用于没有图像的行。