不更新swift4中UItableViewCell的内容

The content of UItableViewCell in not updating swift4

我有一个名为 customContactsTableViewCell 的自定义 uitableviewcell。我正在尝试使用此代码更新 uitableviewCell 内容

let cell1 = self.contactsTableView.dequeueReusableCell(withIdentifier: "contacts", for: IndexPath.init(row: index, section: 0)) as! customContactsTableViewCell
cell1.cellView.image = statusFinal.1
self.contactsTableView.reloadData()

但是没有任何反应。没有错误,cellview 没有更新

如果您是通过 Storyboard 创建的 tableview,只需转到您的 tableview 并将单元格自定义 class 设置为 customContactsTableViewCell 并且您的单元格标识符应为 contacts 如果一切都已经这样设置,那么只需检查这些行。

cell1.cellView.image = statusFinal.1
self.contactsTableView.reloadData()

在 reloadData 之后,它再次重绘 tableview 并通过这个 tableview Delegate 函数在其中设置数据。

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       /// your code
    }

它将再次使用旧数据更新您的数据,只需将此数据 statusFinal.1 保存在您的数据模型中,然后每当您需要重新加载时,它将通过更新的数据进行更新.希望你明白了,如果需要更多信息,请告诉我。

尝试:

let cell1 = tableView.cellForRow(at: IndexPath(row: index, section: 0)) as! customContactsTableViewCell
cell1.cellView.image = statusFinal.1