首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确使用UITableView重新加载RxDataSources?

如何正确使用UITableView重新加载RxDataSources?
EN

Stack Overflow用户
提问于 2022-03-04 13:37:37
回答 1查看 511关注 0票数 1

我正在尝试构建一个tableView,它有许多带有按钮的单元格,我想要做的是,当我单击一个单元格中的按钮时,这个单元格应该转到表格的底部,这是我的代码:

代码语言:javascript
复制
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?

EN

回答 1

Stack Overflow用户

发布于 2022-03-04 16:20:37

这里的基本问题是,在观察发射的观察者中调用onNext。换句话说,在系统完成对当前值的处理之前,您正在释放一个新值。

正如警告所述,处理此问题的最简单方法(很可能是本例中最好的方法)是在sections.bind(to:)之间插入bind(to:)。这样做是将发射延迟到一个周期,这样您的configureCell函数就有机会返回。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71352251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档