我正在尝试构建一个tableView,它有许多带有按钮的单元格,我想要做的是,当我单击一个单元格中的按钮时,这个单元格应该转到表格的底部,这是我的代码:
let datasource = RxTableViewSectionedAnimatedDataSource<ToDoListSection>(
configureCell: { [weak self] _, tableView, indexPath, item in
guard let self = self else { return UITableViewCell() }
let cell = tableView.dequeueReusableCell(withIdentifier: ToDoTableViewCell.reuseID, for: indexPath) as? ToDoTableViewCell
cell?.todoTextView.text = item.text
cell?.checkBox.setSelect(item.isSelected)
cell?.checkBox.checkBoxSelectCallBack = { selected in
if selected {
var removed = self.datasList[indexPath.section].items.remove(at: indexPath.row)
removed.isSelected = selected
self.datasList[indexPath.section].items.append(removed)
self.datasList[indexPath.section] = ToDoListSection(
original: self.datasList[indexPath.section],
items: self.datasList[indexPath.section].items
)
self.sections.onNext(datasList)
} else {
// Todo
}
}
return cell ?? UITableViewCell()
}, titleForHeaderInSection: { dataSource, section in
return dataSource[section].header
})
sections.bind(to: table.rx.items(dataSource: datasource))
.disposed(by: disposeBag)但是,因为我在onNext闭包中发送了一个configureCell事件,所以我收到了一个waring:
检测到⚠️折返异常。
/Users/me/Desktop/MyProject/Pods/RxSwift/RxSwift/Rx.swift:96调试:要调试此问题,可以在
中设置断点并观察调用堆栈。问题:这种行为破坏了可观察的序列语法。
next (error | completed)?这种行为破坏了语法,因为序列事件之间存在重叠。可观察序列是试图在发送以前的事件已经完成之前发送一个事件。解释:这可能意味着您的代码中存在某种意想不到的循环依赖,或者系统没有以预期的方式运行。补救措施:如果这是预期的行为,则可以通过添加.observe(on:MainScheduler.asyncInstance)或以其他方式排队序列事件来抑制此消息。
屏幕上的动作不是我想要的。我该怎么办?如何正确地重新加载TableView?
发布于 2022-03-04 16:20:37
这里的基本问题是,在观察发射的观察者中调用onNext。换句话说,在系统完成对当前值的处理之前,您正在释放一个新值。
正如警告所述,处理此问题的最简单方法(很可能是本例中最好的方法)是在sections.和bind(to:)之间插入bind(to:)。这样做是将发射延迟到一个周期,这样您的configureCell函数就有机会返回。
https://stackoverflow.com/questions/71352251
复制相似问题