当我要用不同的状态填充我的 tableView 时,一个状态行为错误,我确信它是由 tableView 的延迟引起的。请先看视频和图片。
我像这样填充 UITableView:
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId")
cell.state = myStates[indexPath.row]
}
在我的 UITableViewCell
上:
var state: MyCustomDesignState? {
didSet {
self.button.set(state: self.state)
}
}
在我的 UIButton
上:
func set(state: MyCustomDesignState?) {
switch state {
case ...
case .blackBack:
self.backgroundColor = background
self.setTitleColor(textColor, for: .normal)
self.frame = CGRect.init(x: 40, y: 190 - 40, width: 180, height: 34)
self.dropFlatShadow(color: #colorLiteral(red: 0.1008123383, green: 0.1008369699, blue: 0.1008091196, alpha: 1))
self.clipsToBounds = true
self.layer.cornerRadius = 5
}
}
这就是我想要的,也是我得到的:
我的 tableView 是什么样子的:
错误视频:
最佳答案
在您的 TableViewCell
中:尝试调用您当前在状态更改中调用的此方法,如下所示:
override func layoutSubviews() {
super.layoutSubviews()
self.button.set(state: self.state)
}
希望我答对了问题,这对你有帮助。
关于ios - UITableVIew 无法正确渲染 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56360287/