微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

即使正确设置了属性,iOS tableViewCell 也不会在重新加载 tableview 后更新

如何解决即使正确设置了属性,iOS tableViewCell 也不会在重新加载 tableview 后更新

我一直试图找出代码中的问题,但没有找到解决方案。 我有一个下拉库,用于下拉库是 ios Dropdown 1https://github.com/AssistoLab/DropDown 在这里,我自定义了 tableViewCell 并添加一个单选按钮。但是当我尝试重新加载它时,它不会更新其状态,即使在设置状态后它仍然保持不变。

func updateCellBy(text: String,index: Int,isSelected: Bool) {
        self.index = index
        radioButton.isSelected = isSelected
        titleLabel.text = text
        checkBoxButtonWidthConstraint.constant = 20
        radioButtonLeadingConstraint.constant = 15
    }

但是当我滚动这个下拉/tableview 下拉按钮时,状态会得到更新。我仍然在想这有什么问题。测试了上述方法中传入的数据是否正确,但这是正确的。DroppDown image 请注意,此下拉列表位于 collectionViewCell 内,而 collectionViewCell 确实位于视图内。

dropDown.cellNib = UINib(nibName: "TableViewCell",bundle: nil)
            dropDown.customCellConfiguration = { [self] (index: Index,item: String,cell: DropDownCell) -> Void in
                guard let cell = cell as? TableViewCell else { return }
                cell.updateCellBy(text: DropdownArrays.shared.getData()[index],index: index,isSelected: self.cellIndexes.contains(index))
                cell.delegate = self
            }
            dropDown.dataSource = DropdownArrays.shared.getData()

上面是我如何配置下拉菜单。它只是一个带有单元格的表格视图。

为了重新加载下拉菜单,我调用了下面的方法

dropDown.reloadAllComponents()

这确实是在重新加载 DropDown 库中的单元

Reloads all the cells.

    It should not be necessary in most cases because each change to
    `dataSource`,`textColor`,`textFont`,`selectionBackgroundColor`
    and `cellConfiguration` implicitly calls `reloadAllComponents()`.
    */
    public func reloadAllComponents() {
        dispatchQueue.executeOnMainThread {
            self.tableView.reloadData()
            self.setNeedsUpdateConstraints()
        }
    }

但单元格数据没有更新。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。