我正在使用RxDataSources加载和显示一个UITableview。我正在尝试用它持有的项的数量来更新节标题,不管单元格和项如何正确更新,标题仍然是陈旧的。
下面是我为DataSource对象编写的代码:
tableViewDataSource = RxTableViewSectionedAnimatedDataSource<TableViewParticipationSection>(
configureCell: { (_, tableView, _, item) in
return TableViewCellType.transformData(item).cell(inTableView: tableView)
}, titleForHeaderInSection: { dataSource, index in
let sectionModel = dataSource.sectionModels[index]
return "\(sectionModel.items.count)"
})区段标头的标识是{return 0},因为我只有一个区段。
此外,我已经确认,如果我使用此代码:
DispatchQueue.main.asyncAfter(deadline: .now()+3, execute: {
self?.contentView.tableView.reloadData()
})它实际上会更新部分标题,所以它似乎有一些陈旧的问题,但我似乎无法追踪到它。
有没有使用RxDataSources制作动态字幕的经验?
编辑:经过进一步的实验,标题会更新,如果我在表视图中滚动,标题会在某一时刻发生变化。
发布于 2018-10-02 20:12:59
事实证明,部分模型上的标题或任何数据都不包括在diff中,所以无论您做什么,都不会有什么不同。RxDataSource不支持非静态标头。解决方案是创建一个自定义视图,然后自己进行绑定。
发布于 2019-07-22 19:50:20
在我的例子中,我为部分设置了新的空UIView
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let customHeaderViewMulti = tableView.dequeueReusableHeaderFooterView(withIdentifier: "CustomHeaderView") as! CustomHeaderView
return customHeaderView
}
// This is WRONG:
return UIView()
}对于其他情况,您必须使用return nil。
https://stackoverflow.com/questions/52607372
复制相似问题