2014-09-29 50 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; 
}