我有一个tabviewcell,我想动态设置标签文本(tableviewcell的子视图)。但是当我设置标签文本时,heigh显示为0(在屏幕上看不到)。我的代码在下面,但是当我设置文本时,它没有重新计算高度。这是什么问题?
protocol EarningsSemisecureViewDelegate : class {
func enterButtonTapped()
}
class EarningsSemisecureViewCell : UITableViewCell {
var noDataText : String? {
didSet(newValue) {
noDataLabel.text = newValue?.localized()
}
}
private var noDataLabel = RadxLabel()
weak var delegate: EarningsSemisecureViewDelegate?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
customizeView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
customizeView()
}
private func customizeView() {
self.backgroundColor = UIColor.white
self.contentView.backgroundColor = UIColor.white
selectionStyle = UITableViewCell.SelectionStyle.none
noDataLabel.numberOfLines = 0
noDataLabel.textAlignment = .center
noDataLabel.translatesAutoresizingMaskIntoConstraints = false
self.contentView.addSubview(noDataLabel)
noDataLabel.leading = self.contentView.leading + 10
noDataLabel.trailing = self.contentView.trailing - 10
noDataLabel.top = self.contentView.top + 20
let button = WalletButton()
button.setTitle("login.button.enter".localized(), for: .normal)
button.styleNo = 1
button.translatesAutoresizingMaskIntoConstraints = false
button.addTapGestureRecognizer {[weak self] in
if let semiSecureViewDelegate = self?.delegate {
semiSecureViewDelegate.enterButtonTapped()
}
}
self.contentView.addSubview(button)
button.top = noDataLabel.bottom + 30
button.trailing = self.contentView.trailing - 10
button.leading = self.contentView.leading + 10
}
}
let semisecureViewCell = EarningsSemisecureViewCell()
semisecureViewCell.noDataText = "earnings.not.login.info"
return semisecureViewCell
单元格在tableviewdatasource中返回。