【发布时间】:2021-05-17 08:42:41
【问题描述】:
我的视图控制器中有一个带有自定义单元格的表格视图。在单元格中,我有一个应该做某事的功能。我有一个正在执行的打印语句。
@objc func cellButtonTapped() {
cellText.backgroundColor = .red
print("cell button tapped")
}
当我点击按钮时,我确实在控制台中看到了打印语句,但它并没有像我想要的那样改变单元格背景颜色。
这是tableViewCell中的cellText
let cellText : UITextField = {
let cellText = UITextField()
cellText.isUserInteractionEnabled = false
return cellText
}()
这是它在单元格中的布局方式。我不认为它的布局很重要
override func layoutSubviews() {
super.layoutSubviews()
contentView.addSubview(cellText)
contentView.addSubview(cellButton)
cellText.frame = CGRect(x: 0,
y: 0,
width: contentView.width - 30,
height: contentView.height)
cellButton.frame = CGRect(x: cellText.right, y: 0, width: 30, height: contentView.height)
}
【问题讨论】:
-
什么是
cellText? -
请分享完整的上下文
-
我更新了信息。希望这能给你更多的背景
标签: ios swift uitableview tableview viewcontroller