0
我正在使用我自己的uitableviewcell的uitableview。我想在運行時以編程方式完成所有操作,而不使用佈局管理器。如何佈局我自己的UITableViewCell
我現在的問題是,我的單元格不顯示在我的uitableview中。我明白,因爲我沒有定義單元中元素的大小(佈局)。那是我不知道該怎麼做的。
我用我的UITableViewCell
如下:
import UIKit
class CellResult: UITableViewCell {
var cellImage: UIImageView
var cellTitle: UILabel
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
cellImage = UIImageView();
cellTitle = UILabel();
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
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
}
}
我失去了一些東西像view.addsubview(cellImage)
。如何以編程方式顯示我的單元格中的元素?
只需將您的圖像/標題視圖添加爲單元格'contentView'的子視圖並將它們佈置在'layoutSubviews'中(如果您不想定義自動佈局約束)。 – pNre