ios - 实时更新自定义表格部分标题视图内容
问题描述
我有一个自定义tableView
标题的问题,即我无法实时更新表格部分内容。
这是演示我的问题的示例代码:
//SomeViewController.swift
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if let infoHeaderView = InfoHeaderView.viewFromNib as? InfoHeaderView {
infoHeaderView.update(with: someContent)
updateMethod = { newContent in
infoHeaderView.update(with: newContent)
}
}
}
...
updateMethod(someContent)
...
//InfoHeaderView.swift
func update(with content: Content) {
someLabel.text = content.textProperty
}
注意:我想在不重新加载表或单个部分的情况下实现这一点。我只想更新自定义表格部分视图中的单个标签。
我希望在 updateMethod 调用时更改标签文本,但它不会发生。可能是什么问题呢?
编辑:
当我将部分标题滚动到顶部并让它返回时,它运行良好。
解决方案
使用要更改标题的部分的索引,如下所示:
if let headerView = self.tableView.headerView(forSection: <section number>) as? InfoHeaderView {
headerView.update(with: content)
}
但可能要使这种方法起作用,您的标题视图应该是类型的子类UITableViewHeaderFooterView
推荐阅读
- kotlin - Kotlin 在进入下一个索引之前等待 for 循环中的协程
- python - 列是否存在某些条件的标志
- swift - 从 React Native asyncstorage 快速获取
- reactjs - 如何强制更新功能组件?
- javascript - 如何显示 js 对象名称及其所有属性值?
- django - html文件中的Django Back和Next按钮
- visual-studio-code - 如何打开提交 VS CODE 的所有文件
- google-sheets - 有没有办法使用与谷歌表格中的行和列相同的字段来计算列之间的唯一出现次数?
- shopware - Shopware 6:为什么在自定义插件的 src/Resources/app/storefront/src/main.js 中添加 if 条件 if (module.hot)
- javascript - FS 替代反应