Iphone 从自定义uitablecell视图中删除UIimage

Iphone 从自定义uitablecell视图中删除UIimage,iphone,uitableview,Iphone,Uitableview,我想从某些表格单元格中删除图像: 我有一个自定义表格单元格,包括图像、标签、字幕 cellIcon,cellHead,cellStandfirst 有些单元格没有图像,因此我希望标签和副标题向后扩展以填充图像留下的空间(就像标准UITable没有自定义单元格类时的行为一样) 目前我正在打电话 [cell shortCell:cell.bounds.size.width]; 从tableViewController调用 - (void)shortCell:(float)myfloat; {

我想从某些表格单元格中删除图像:

我有一个自定义表格单元格,包括图像、标签、字幕

cellIcon,cellHead,cellStandfirst

有些单元格没有图像,因此我希望标签和副标题向后扩展以填充图像留下的空间(就像标准UITable没有自定义单元格类时的行为一样)

目前我正在打电话

[cell shortCell:cell.bounds.size.width];
从tableViewController调用

- (void)shortCell:(float)myfloat; {
    [cellHead setFrame:CGRectMake(
        CELL_CONTENT_MARGIN, 
        3.0f, 
        myfloat - (CELL_CONTENT_MARGIN * 2), 
        24.0f)];
    [cellStandfirst setFrame:CGRectMake(
        CELL_CONTENT_MARGIN, 
        25.0f, 
        myfloat - (CELL_CONTENT_MARGIN * 2), 
        34.0f)];
}
这很好,但我觉得默认的表视图必须删除图像,而不是调整标签的大小

我试着把不同的

[cellIcon removeFromSuperview];
在cell类中,以及

[cell.cellIcon remove];
在tableview控制器中,但无法使任何内容正常工作

是否可以从某些单元格中删除表格单元格图像,以便标签自动调整大小?

您只需尝试:

cell.cellIcon = nil;
或:

我不知道它是否有效,但你只要试试。

你可以试试

cellIcon.hidden=YES;

属性执行此操作……

子视图无法自动填充空白。你必须坚持你目前的方法

如果要从
超级视图
中删除空的
单元格图标
,必须记住单元格是重复使用的。因此,如果它的
nil

使用此代码,则必须以编程方式重新初始化它

if ( __what-test-is-needed__) {
    [cell cellIcon:@"your_image.png"];

} else {
    [cell cellIcon:nil];
    [cell shortCell:cell.bounds.size.width];
}
然后在细胞类

#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f

@implementation StoryCellViewController

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code.
    }
    return self;
}



- (void)cellHead:(NSString *)_text;{
    cellHead.text = _text;
    //NSLog(@"Width: %f", self.bounds.size.width);
}

- (void)cellIcon:(NSString *)_text;{
    cellIcon.image = [UIImage imageNamed:_text];
}

- (void)cellStandfirst:(NSString *)_text;{
    cellStandfirst.text = _text;


}

- (void)shortCell:(float)myfloat; {
    // NSLog(@"Width: %f", self.bounds.size.width);
    // NSLog(@"Float: %f", myfloat);
    [cellHead setFrame:CGRectMake(
                               CELL_CONTENT_MARGIN, 
                               4.0f, 
                               myfloat - (CELL_CONTENT_MARGIN * 2), 
                               24.0f)];
    [cellStandfirst setFrame:CGRectMake(
                                    CELL_CONTENT_MARGIN, 
                                    26.0f, 
                                    myfloat - (CELL_CONTENT_MARGIN * 2), 
                                    34.0f)];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state.
}

我已经在调用它了,它只是在uimageview中放置了一个nil图像(即没有图像),但它并没有移除uimageview在视图中分配给自己的空间
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f

@implementation StoryCellViewController

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code.
    }
    return self;
}



- (void)cellHead:(NSString *)_text;{
    cellHead.text = _text;
    //NSLog(@"Width: %f", self.bounds.size.width);
}

- (void)cellIcon:(NSString *)_text;{
    cellIcon.image = [UIImage imageNamed:_text];
}

- (void)cellStandfirst:(NSString *)_text;{
    cellStandfirst.text = _text;


}

- (void)shortCell:(float)myfloat; {
    // NSLog(@"Width: %f", self.bounds.size.width);
    // NSLog(@"Float: %f", myfloat);
    [cellHead setFrame:CGRectMake(
                               CELL_CONTENT_MARGIN, 
                               4.0f, 
                               myfloat - (CELL_CONTENT_MARGIN * 2), 
                               24.0f)];
    [cellStandfirst setFrame:CGRectMake(
                                    CELL_CONTENT_MARGIN, 
                                    26.0f, 
                                    myfloat - (CELL_CONTENT_MARGIN * 2), 
                                    34.0f)];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state.
}