2016-07-20 61 views

回答

1

寫入viewDidLoad

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

PLZ檢查我的問題在下面的評論 – Amitkumar

2

簡單地使用像

目標-C

- (void)viewDidLoad 
{ 
... 
... 
self.tableView.estimatedRowHeight = 100.0; 
self.tableView.rowHeight = UITableViewAutomaticDimension; 
} 

夫特

override func viewDidLoad() { 


     self.tableView.estimatedRowHeight = 80 
     self.tableView.rowHeight = UITableViewAutomaticDimension 

} 

Objective-C的

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
return 80; // customize the height 
} 

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

斯威夫特

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
return 80 // customize the height 
} 

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
return UITableViewAutomaticDimension 
} 

終於定下您label.numofLines = 0在屬性或程式設計

+0

使用任何一個選擇,肯定工作 –

+0

PLZ您在下面的評論 – Amitkumar

2

我想知道爲什麼知道你正在尋找一種不使用自動佈局的方法。我相信以前發佈的答案是使用自動佈局

隨着自動佈局

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

的解決方案,你可以設置multiline label根據標籤

沒有自動佈局

的內容沒有自動版式您需要展開分別計算每個單元格的高度(height for each labels +邊距),並返回UITableView數據源方法- tableView:heightForRowAtIndexPath:中的值。

0

謝謝,但問題沒有解決 請檢查圖像

  1. 之前沒有使用上述的解決方案我的表視圖看起來更好,但使用你的幫助後,文本沒有調整

enter image description here

使用self.tableView.rowHeight = UITableViewAutomaticDimension;heightforcell方法一切都搞砸

我的tableview與分鏡請檢查尺寸檢查標籤的自動調整部分

enter image description here

請告訴我錯了我在這裏做什麼?

+0

我的問題,你必須設置標籤的行數爲0,你使用'self.tableView.estimatedRowHeight =當前行身高' ' –

相關問題