ios - UITableVIew 无法正确渲染 UITableViewCell

标签 ios swift uitableview

当我要用不同的状态填充我的 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
    }
}

这就是我想要的,也是我得到的:

enter image description here

我的 tableView 是什么样子的:

错误视频:

https://streamable.com/ki7vx

最佳答案

在您的 TableViewCell 中:尝试调用您当前在状态更改中调用的此方法,如下所示:

override func layoutSubviews() {
          super.layoutSubviews()
          self.button.set(state: self.state)
    }

希望我答对了问题,这对你有帮助。

关于ios - UITableVIew 无法正确渲染 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56360287/

相关文章:

c# - UITextView - 设置边框颜色

ios - 只添加当前不存在的对象到 Realm 数据库

ios - 在每个表格 View 单元格中使用 UIImagePickerController

ios - 我在理解如何使用自动布局的逻辑时遇到问题

swift - 动态 UIWebView 高度和 UITableViewCell 调整大小

ios - 问题同时选择所有表格 View 单元格 | swift

ios - 对于 UIControlEvent 对象的 editingDidBegin 属性,术语 'session' 在外行术语中意味着什么?

Swift 按字符串 double 排序结构数组

ios - 如何拖动和关闭 View Controller ?

ios - 搜索栏故障