2017-02-18 61 views
1

我在快速設置tableview單元格行高時,在滾動行高變化時,請檢查屏幕快照。 enter image description hereTableview根據swift中的內容動態設置行高?

它第一次滾動完成多次滾動的高度並不合適。我使用了太多的自定義的tableview細胞 在viewDidLoad中 我加入這個

self.tableView.rowHeight = UITableViewAutomaticDimension 

,並還增加了這些委託的方法。

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

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

任何人都可以指導我以正確的方式實現這一目標。

+0

請把這個放在你的** cellForRowAtIndexPath **方法中'yourLabel.numberOfLines = 0'和 'yourLabel.sizeToFit()' – iDeveloper

+0

這不是帶有一個標籤的。我用了兩個很多標籤。 –

+0

你有沒有給圖像和標籤之間的適當限制? – iParesh

回答

1

你可以嘗試這樣的事:

tableView.rowHeight = UITableViewAutomaticDimension 
tableView.estimatedRowHeight = 160 

而在你的故事板,你需要設置TOP & BOTTOM約束你的標籤。沒有其他的。

+0

好的。身高和寬度我也設置 –

+0

你也可以設置他們,但我不會推薦它。 –

+0

謝謝你Matthijs ..我想使用textview,uiviews,按鈕和標籤根據我想獲得高度的條件。可能嗎 –

相關問題