2014-09-29 53 views
0

我有一个自定义uitableviewcell无法更改UITableViewCell contentView高度

我想根据一些条件改变它的高度。 我怎样才能做到这一点?

我试着在cellForRowAtIndexPath这样做 -

if (cell.newsFeedImage.image == NULL) 
{ 
    NSLog(@"NULL"); 
    cell.uDisplayImage.frame = CGRectMake(20, 20, 20, 20); 
} 

出现日志消息,但帧永远不会改变。

请帮忙。

+1

[设置自定义UITableViewCells高度(可能重复http://stackoverflow.com/questions/494562/setting-custom-uitableviewcells-height) – Szu 2014-09-29 11:05:27

回答

1

细胞的高度在数据源的tableView方法

heightForRowAtIndexPath

+0

我知道, 但我也想降低内部视图的高度在uitableviecell – 2014-09-29 10:58:04

+0

这个方法是委托协议的一部分。你不用它来设置高度,你从它返回高度。 – 2014-09-29 10:58:36

1

尝试做这heightForRowAtIndexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CustomCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; 
    if (cell.newsFeedImage.image == nil) { 
     cell.uDisplayImage.frame = CGRectMake(20, 20, 20, 20); 
    } 
    else return 40; 
}