2016-09-15 78 views
2

enter image description here中的UITableView動態細胞高度問題使用自動版式?

我必須計算單元格的高度取決於兩個標籤,左標籤和右標籤。左標籤可以有空字符串。如果剩下的標籤是空的,我想給一個特定的固定高度,否則它會佔用左標籤高度。 廣東話能夠給予一定的高度時,標籤是空 此代碼不能正常工作

self.tableView.estimatedRowHeight = 50 

enter image description here

回答

2

您爲您的標籤都應該是約束,

top,bottom,leading and trailing

,並從細胞到兩個標籤的頂部和底部的viewDidload

self.tableView.estimatedRowHeight = 50 
self.tableView.rowHeight = UITableViewAutomaticDimension; 
+0

感謝您的答案在我的案例中工作 – sukhmeet

1

設置限制設置下面的代碼。 然後在您的視圖控制器中添加以下代碼

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 50; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 
    return UITableViewAutomaticDimension; 
}