UiTableViewCell 动态高度适用于 iphone 而不是 ipad 尺寸 class
UiTableViewCell Dynamic height works on iphone not ipad size class
所以基本上我有任何尺寸 class 用于 iPhone 和常规常规用于 iPad。话虽如此,我有一个自定义 UITableViewCell
并且我有 iPhone 的单元格自动调整大小。我垂直布置约束以帮助它了解单元格的大小。
问题出在 iPad 大小上 class 我正在做同样的事情,显然布局有点不同,但我检查了每个元素,它有顶部和底部以及高度限制在它上面 UITableViewCell
和 iPhone 布局一样高。
这是我为那个场景编写的代码:
import UIKit
class TruckListMainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var truckNames = ["This Truck Test"]
var truckImages = ["default-truck.png"]
var oneAverages = ["5.02"]
var twoAverages = ["6.02"]
var threeAverages = ["7.02"]
var fourAverages = ["8.02"]
var oneLabels = ["30 Day MPG"]
var twoLabels = ["60 Day MPG"]
var threeLabels = ["90 Day MPG"]
var fourLabels = ["Lifetime MPG"]
@IBOutlet weak var truckListTable: UITableView!
@IBOutlet weak var openMenu: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.truckListTable.rowHeight = UITableViewAutomaticDimension
self.truckListTable.estimatedRowHeight = 200.0
openMenu.target = self.revealViewController()
openMenu.action = Selector("rightRevealToggle:")
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return truckNames.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! truckList
// Configure the cell...
cell.truckName.text = truckNames[indexPath.row]
cell.truckImage.image = UIImage(named: truckImages[indexPath.row])
cell.averageOne.setTitle(oneAverages[indexPath.row], forState: UIControlState.Normal)
cell.averageTwo.setTitle(twoAverages[indexPath.row], forState: UIControlState.Normal)
cell.averageOne.setTitle(threeAverages[indexPath.row], forState: UIControlState.Normal)
cell.averageOne.setTitle(fourAverages[indexPath.row], forState: UIControlState.Normal)
cell.labelOne.setTitle(oneLabels[indexPath.row], forState: UIControlState.Normal)
cell.labelTwo.setTitle(twoLabels[indexPath.row], forState: UIControlState.Normal)
cell.labelThree.setTitle(threeLabels[indexPath.row], forState: UIControlState.Normal)
cell.labelFour.setTitle(fourLabels[indexPath.row], forState: UIControlState.Normal)
return cell
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.backgroundColor = UIColor.clearColor()
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor(red: 202/255.0, green: 202/255.0, blue: 202/255.0, alpha: 1)
} else {
cell.backgroundColor = UIColor(red: 240/255.0, green: 240/255.0, blue: 240/255.0, alpha: 1)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
任何帮助将不胜感激,我不会 post 在这里,但我已经为这个问题苦苦挣扎了将近 2 天。如果我可以 post 图片我会的,我知道这会有助于查看限制条件。
I checked every element and it has a top and bottom and height constraint on it yet the UITableViewCell is as high as the iPhone layout
您可能对单元格高度的确定方式感到困惑。如果您不希望单元格高度由内部约束决定,您需要将 table 视图的 rowHeight
属性 设置为某个实际数字( 而不是 UITableViewAutomaticDimension
).
所以基本上我有任何尺寸 class 用于 iPhone 和常规常规用于 iPad。话虽如此,我有一个自定义 UITableViewCell
并且我有 iPhone 的单元格自动调整大小。我垂直布置约束以帮助它了解单元格的大小。
问题出在 iPad 大小上 class 我正在做同样的事情,显然布局有点不同,但我检查了每个元素,它有顶部和底部以及高度限制在它上面 UITableViewCell
和 iPhone 布局一样高。
这是我为那个场景编写的代码:
import UIKit
class TruckListMainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var truckNames = ["This Truck Test"]
var truckImages = ["default-truck.png"]
var oneAverages = ["5.02"]
var twoAverages = ["6.02"]
var threeAverages = ["7.02"]
var fourAverages = ["8.02"]
var oneLabels = ["30 Day MPG"]
var twoLabels = ["60 Day MPG"]
var threeLabels = ["90 Day MPG"]
var fourLabels = ["Lifetime MPG"]
@IBOutlet weak var truckListTable: UITableView!
@IBOutlet weak var openMenu: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.truckListTable.rowHeight = UITableViewAutomaticDimension
self.truckListTable.estimatedRowHeight = 200.0
openMenu.target = self.revealViewController()
openMenu.action = Selector("rightRevealToggle:")
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return truckNames.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! truckList
// Configure the cell...
cell.truckName.text = truckNames[indexPath.row]
cell.truckImage.image = UIImage(named: truckImages[indexPath.row])
cell.averageOne.setTitle(oneAverages[indexPath.row], forState: UIControlState.Normal)
cell.averageTwo.setTitle(twoAverages[indexPath.row], forState: UIControlState.Normal)
cell.averageOne.setTitle(threeAverages[indexPath.row], forState: UIControlState.Normal)
cell.averageOne.setTitle(fourAverages[indexPath.row], forState: UIControlState.Normal)
cell.labelOne.setTitle(oneLabels[indexPath.row], forState: UIControlState.Normal)
cell.labelTwo.setTitle(twoLabels[indexPath.row], forState: UIControlState.Normal)
cell.labelThree.setTitle(threeLabels[indexPath.row], forState: UIControlState.Normal)
cell.labelFour.setTitle(fourLabels[indexPath.row], forState: UIControlState.Normal)
return cell
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.backgroundColor = UIColor.clearColor()
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor(red: 202/255.0, green: 202/255.0, blue: 202/255.0, alpha: 1)
} else {
cell.backgroundColor = UIColor(red: 240/255.0, green: 240/255.0, blue: 240/255.0, alpha: 1)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
任何帮助将不胜感激,我不会 post 在这里,但我已经为这个问题苦苦挣扎了将近 2 天。如果我可以 post 图片我会的,我知道这会有助于查看限制条件。
I checked every element and it has a top and bottom and height constraint on it yet the UITableViewCell is as high as the iPhone layout
您可能对单元格高度的确定方式感到困惑。如果您不希望单元格高度由内部约束决定,您需要将 table 视图的 rowHeight
属性 设置为某个实际数字( 而不是 UITableViewAutomaticDimension
).