ios - UITableVIew 无法正确渲染 UITableViewCell
问题描述
当我要用不同的状态填充我的 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)
}
希望我的问题是正确的,这对你有帮助。
推荐阅读
- python - Tkinter 画布十六进制代码颜色不一致?
- php - PHP mbstring 不起作用,但我设置了所有内容
- c# - 如何从 .NET 5 Worker Service 中的 app.config 读取数据?
- c# - LottieSharp(WPF) 在与 UWP 项目桥接时崩溃
- mysql - 为什么 MySQL 更喜欢 ENUM('N','Y') 而不是 BOOL?
- flutter - 如何仅针对当前页面制作具有不同页面大小的 PageView
- javascript - this.functionName 未定义
- windows-10 - NFC-list 使用 ACR122U 读写器无法找到 USB 总线(没有此类文件或目录)
- c# - 当另一个应用程序全屏运行时,WPF 应用程序无法正确绘制
- swift - Swift 中的类绑定协议细化