2016-11-08 57 views
0

我想讓我的最後一個單元格獲取tableview中留下的所有剩餘空間。所以我寫了這段代碼:最後一個單元格必須佔用表格中剩餘的所有空間查看

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    if indexPath.row == tableView.numberOfRows(inSection: 0) - 1 { 
     let sectionheight: CGRect = tableView.rect(forSection: 0) 
     let tableViewFrame: CGRect = tableView.frame 
     let height: CGFloat = tableViewFrame.size.height - (sectionheight.size.height - 100) 


     cell.frame.size.height = height 
     cell.layoutIfNeeded() 
    } 
} 

,並在heightForRow該小區我只返回一個像100

的問題是,計算出的高度是正確的值,但電池不更改。

如何確保細胞高度發生變化?

回答

1

你應該做的高度計算在heightForRow,而不是在willDisplayCell,你也可以先保存一些財產willDisplayCell然後調用tableView.beginUpdateendUpdate強制重新計算單元格高度

細胞並沒有改變,因爲實現代碼如下處理單元格高度,不是細胞,細胞只控制它的內容高度

相關問題