我收到此错误:
assert(代理=== DelegateProxy.currentDelegate(用于:对象),“代理 从第一次设置开始就发生了变化。
原文:(代理)
现有: (字符串(描述:DelegateProxy.currentDelegate(用于:对象)))“)
我有两个在不同状态下处理xib故事板的可观察对象,但是一旦其中一个被加载,我就会收到上述错误,我尝试使用self.tableView.delegate = nil & self.tableView.dataSource = nil
,但是却在{{1 }}函数。我的问题是在出现此错误之前我不知道如何处理它:
断言失败:代理自首次设置起便发生了更改。
原件:
.bind(to:)
如何在数据Observables触发之前将tableview设置为nil?
此功能可以警告您已经有一个委托(或数据) 源)设置在先前的某个位置。您要执行的操作? 会清除该委托(数据源),这意味着依赖于所设置的委托(数据源)的某些功能可能会停止工作。如果可以的话,请尝试在此操作之前将委托(数据源)设置为
.asObservable().bind(to:(tableView?.rx.items(cellIdentifier: aTableViewCell.Identifier, cellType: HaTableViewCell.self))! func initTableView() { // pull to refresh aViewModel .isLoading .asObservable() .subscribe({ (loading) in if loading.element == false { } else { self.tableView!.delegate = self // loads a shimmering view self.tableView!.dataSource = self } }) .disposed(by: disposeBag) aViewModel .datas .asObservable() .bind(to:(tableView?.rx.items(cellIdentifier: aTableViewCell.Identifier, cellType: HaTableViewCell.self))!) { (index, element, cell) in // when the data is fired load this tableview cell }.disposed(by: disposeBag) }
。
答案 0 :(得分:0)
对我来说,要达到的目标还不是很清楚。
通常,与RxDataSources一起使用时,您应该不设置“ tableView.dataSource”或“ tableView.delegate”。
如果要将不同的可观察对象作为数据源绑定到同一tableView,则需要'.switchLatest()'运算符。
答案 1 :(得分:0)
每次通过RxCocoa与委托相关联时,都需要确保将一次性物品清理干净,以便与其他物品重复使用。
很快,您无需设置为nil,指向其他内存插槽即可完成工作。
func refreshTableView() {
disposable = DisposeBag()
// pull to refresh
aViewModel
.datas
.asObservable()
.bind(to:(tableView?.rx.items(cellIdentifier: aTableViewCell.Identifier, cellType: HaTableViewCell.self))!) { (index, element, cell) in
// when the data is fired load this tableview cell
}.disposed(by: disposeBag)
}