我已经开始学习如何在swift中编写iOS代码,在我的应用程序中我尝试使用自定义cels的表视图,在单元格中有四个标签和两个按钮,我的问题是按钮和两个标签不是出于某种原因显示,我已经检查了一些教程并搜索了stackoverflow,但我找不到任何问题的答案。
这就是我的故事板的外观:
这是我的CustomCell类:
import UIKit
class CustomCell: UITableViewCell {
@IBOutlet weak var numberVehicle: UILabel!
@IBOutlet weak var nameVehicle: UILabel!
@IBOutlet weak var showHideButton: UIButton!
@IBOutlet weak var focusButton: UIButton!
@IBOutlet weak var hideLabel: UILabel!
@IBOutlet weak var focusLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
这是我在控制器中的tableView函数的代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as CustomCell
let key = indexPath.row
let vehicle = vehicles[key]
let image = UIImage(named: "button.png") as UIImage?
cell.nameVehicle.text = vehicle.name
cell.numberVehicle.text = vehicle.number
cell.showHideButton.setBackgroundImage(image, forState: .Normal)
cell.focusButton.setBackgroundImage(image, forState: .Normal)
return cell
}
这就是它在iOS模拟器中的外观:
任何帮助将非常感激
答案 0 :(得分:3)
请你在故事板底部布局试试这个。但首先要确定
use Auto Layout
已勾选。