【发布时间】:2023-04-03 10:18:01
【问题描述】:
我有自定义 UITableViewCell 属性count: Int?。根据这个属性,我渲染了 UITextFields 的数量。 (例如count == 1 --> 一个 UITextField,count == 2 --> 两个 UITextField)。
稍后当某些事件发生时,我想为此标签设置新值。这是我的工作:
在我的 UIViewController 中:
@objc func onDidReceiveEvent(_ notification: Notification) {
guard let count = notification.object as? Int else { return }
guard let cell = self.tableView.cellForRow(at: IndexPath(row: 2, section: 0)) as? MyCustomCell else { return }
cell.count = count
self.tableView.reloadRows(at: [IndexPath(row: 2, section: 0)], with: .automatic)
// I also tried self.tableView.reloadData()
}
我在override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) 中设置了断点,我看到在这段代码之后单元格正在更新,但属性count 没有更新。我做错了什么?
【问题讨论】:
标签: ios swift uitableview