[英]How to calculate the height of a custom expand/collapsable UITableViewCell dynamically
[英]How to dynamically calculate height of UITableViewCell according to device
我現在有一個UITableViewController
,並且有x個用於UITableView
單元格,它與屏幕的高度相同。 我不想滾動UITableView
,我想將整個屏幕分成相同高度的x個部分。
我是否必須先檢查設備類型,然后計算每個單元的高度? 然后有很多if
或switch
語句。 什么是實現這一目標的最佳方法?
謝謝。
假設您有一個導航欄,請嘗試以下操作:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let screenHeight = UIScreen.mainScreen().bounds.height
return (screenHeight - 64) / <number of cells>
}
如果您沒有導航欄,只需更換
return (screenHeight - 64) / <number of cells>
同
return screenHeight / <number of cells>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.