1

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

编辑:经过进一步的实验,标题会更新,如果我在表格视图中滚动,标题会在某个时候发生变化。

4

2 回答 2

0

在我的情况下,我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对于其他情况,您必须这样做。

于 2019-07-22T11:50:20.283 回答
0

事实证明,标题或截面模型上的任何数据都不包含在差异中,所以无论你做什么,它都不会产生影响。RxDataSource不支持非静态标题。解决方案是制作自定义视图并自己进行绑定。

于 2018-10-02T12:12:59.297 回答