2011-12-17 86 views

回答

32

您需要實現

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

方法在UITableViewDelegate

+0

哇哦謝謝 – user973985 2011-12-17 09:53:53

15

你可以做這樣的..

//Change the Height of the Cell [Default is 44]: 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    if (indexPath.section == 0) { 
    if (indexPath.row == 1) { 
    return 90; 
    } 
    } 
    return 44; 
} 

我希望這將幫助你..

+0

其實我在做類似的事情我使它更大相比文字標籤長度 – user973985 2011-12-17 10:25:09

+1

默認實際上是44分 – Daniel 2013-05-22 19:16:05

-2

您可以使用此代碼,改變不同的tableview

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(tableView == tableView1) 
    { 
     return 55; 
    } 
    else if(tableView == tableView2) 
    { 
     return 75; 
    } 
} 

這個高度可以幫助你。

6

有2個步驟來更改表格單元格的高度,而不會任何額外的代碼:

  1. Table View從你的故事板中選擇。在Size Inspector更改Row Height
  2. 選擇您的Table View Cell,當它在Size Inspector中選中時,請更改Row Height

請注意,您MUST設置BOTH表視圖的Row Height屬性和表格視圖單元格的Row Height屬性。

如果您只設置了其中一個,它將不起作用。

0

我發現this answer是改變表格視圖單元格高度最豐富和最新的。

TL; DR

  1. 上的viewDidLayoutSubviews方法您表視圖使你的自動佈局約束
  2. 啓用行高度估算時要格外小心。

    self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.estimatedRowHeight = 44.0; //設置爲任何你的「平均」單元格高度是

相關問題