【发布时间】:2015-07-23 16:28:57
【问题描述】:
所以基本上我有用于 iPhone 的 any any size 类和用于 iPad 的常规常规类。话虽如此,我有一个自定义的UITableViewCell,并且我有 iPhone 的单元格自动调整大小。我垂直布置了约束,以帮助它知道单元格的大小。
问题出在 iPad 尺寸类上,我正在做同样的事情,显然布局有点不同,但我检查了每个元素,它有顶部和底部以及高度限制,但 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.
}
*/
}
任何帮助将不胜感激,我不会在这里发帖,但我已经为这个问题苦苦挣扎了将近 2 天。如果我可以发布图片,我知道这将有助于了解限制。
【问题讨论】:
标签: swift uitableview ios8 autolayout