2011-05-20 65 views
0

删除的UIImage我想从某些表格单元中删除IBOutlet中的UIImage:从定制uitablecell视图

我有包括图像,一个标签,字幕的定制表格单元格...

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)]; 
} 

工作正常

,但是这让我感到默认表视图必须删除图像,而不是调整标签。

我在的tableview控制器试图把的

[cellIcon removeFromSuperview]; 
在细胞类

变种,并

[cell.cellIcon remove]; 

,但不能得到任何工作

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

回答

0

在细胞类

#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. 
} 
1

你只是试图

cell.cellIcon = nil; 

或者

[cell setCellIcon:nil]; 

我不知道它会工作或没有,但你只是尝试.....

感谢名单....

+0

使用此代码

if (__what-test-is-needed__) { [cell cellIcon:@"your_image.png"]; } else { [cell cellIcon:nil]; [cell shortCell:cell.bounds.size.width]; } 

然后它工作正常...? – SJS 2011-05-20 10:48:09

+0

我已经调用过它,它只是将一个零图像(即没有图像)放入uimageview中,但它不会删除uimageview分配给视图的空间 – JulianB 2011-05-20 13:34:09

0

你可以试试

cellIcon.hidden=YES; 

属性这样做......

0

子视图无法自动填充空白空间。你将不得不坚持你目前的方法。

如果您要从superview中删除空的cellIcon,则必须牢记单元格已被重新使用。所以你必须以编程方式重新初始化它,如果它的nil