[英]RxDataSources not updating section header title
我正在使用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
動態標題的經驗
編輯:經過進一步的實驗,標題將更新,如果我在表格視圖中滾動,標題會在某個時候更改。
事實證明,差異中不包含標題或截面模型上的任何數據,因此無論您做什么,都不會有所作為。 RxDataSource
不支持非靜態標頭。 解決方案是創建自定義視圖並自己進行綁定。
在我來說,我設置新的空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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.