我真的無法在檔案或其他地方找到它,但是有沒有辦法使用 RxDatasources 提供從 nib 加載的自定義頁眉和頁腳?
例如,我將這樣的單元出列:
let dataSource = RxTableViewSectionedAnimatedDataSource<CommentsSectionModel>(
configureCell: { dataSource, tableView, indexPath, item in
if let cell = tableView.dequeueReusableCell(withIdentifier:
item.cellIdentifier, for: indexPath) as? BaseTableViewCell{
cell.setup(data: item.model)
return cell
}
return UITableViewCell()
})
我看不出有什么東西與configureCell(except titleForHeaderInSection) 一起讓我出列/配置可重用的頁眉/頁腳(標準viewForHeaderInSection和viewForFooterInSection委托方法提供的東西)。
uj5u.com熱心網友回復:
自定義頁眉/頁腳不是 UITableViewDataSource 介面的一部分,因此它不是 RxDataSource 可以提供的。
如果你愿意,你可以按照我關于如何將 Swift 委托轉換為 RxSwift Observables 的文章進行操作,并為此創建一個表視圖委托......它不是庫的一部分,因為表視圖委托不符合推送介面。
extension Reactive where Base: UITableView {
var delegate: UITableViewDelegateProxy {
return UITableViewDelegateProxy.proxy(for: base)
}
var viewForHeaderInSection: Binder<[Int: UIView]> {
Binder(delegate) { del, value in
del.viewForHeaderInSection.accept(value)
}
}
var viewForFooterInSection: Binder<[Int: UIView]> {
Binder(delegate) { del, value in
del.viewForFooterInSection.accept(value)
}
}
}
final class UITableViewDelegateProxy
: DelegateProxy<UITableView, UITableViewDelegate>
, DelegateProxyType
, UITableViewDelegate {
public static func registerKnownImplementations() {
self.register { UITableViewDelegateProxy(parentObject: $0) }
}
static func currentDelegate(for object: UITableView) -> UITableViewDelegate? {
object.delegate
}
static func setCurrentDelegate(_ delegate: UITableViewDelegate?, to object: UITableView) {
object.delegate = delegate
}
init(parentObject: UITableView) {
super.init(
parentObject: parentObject,
delegateProxy: UITableViewDelegateProxy.self
)
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
viewForHeaderInSection.value[section]
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
viewForFooterInSection.value[section]
}
fileprivate let viewForHeaderInSection = BehaviorRelay<[Int: UIView]>(value: [:])
fileprivate let viewForFooterInSection = BehaviorRelay<[Int: UIView]>(value: [:])
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/396580.html
上一篇:如何通過導航控制器傳遞委托?
