【发布时间】:2014-11-26 08:11:14
【问题描述】:
我已经开始学习如何在 swift 中为 iOS 编写代码,在我的应用程序中,我尝试使用带有自定义 cel 的表格视图,单元格中有四个标签和两个按钮,我的问题是按钮和两个标签不是出于某种原因,我检查了一些教程并搜索了 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 模拟器中的样子: 任何帮助将不胜感激
【问题讨论】:
-
按钮需要自动布局约束。
标签: ios uitableview swift xcode6.1