Ios 如何允许编辑RxDataSources支持的表视图?

Ios 如何允许编辑RxDataSources支持的表视图?,ios,swift,uitableview,rx-swift,rxdatasources,Ios,Swift,Uitableview,Rx Swift,Rxdatasources,我正在构建一个由RxDataSources支持的表视图。我想启用此表视图的编辑,以便用户可以删除项目 我目前有以下代码: var strings = [String]() { didSet { observable.accept(strings) } } let observable = BehaviorRelay(value: [String]()) let disposeBag = DisposeBag() override func viewDidLoa

我正在构建一个由RxDataSources支持的表视图。我想启用此表视图的编辑,以便用户可以删除项目

我目前有以下代码:

var strings = [String]() {
    didSet {
        observable.accept(strings)
    }
}

let observable = BehaviorRelay(value: [String]())
let disposeBag = DisposeBag()

override func viewDidLoad() {
    tableView.dataSource = nil
    let dataSource = RxTableViewSectionedAnimatedDataSource<StringSection>(configureCell:  {
        (dataSource, collectionView, indexPath, string) -> UITableViewCell in
        let cell = collectionView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = string
        return cell
    })

    observable.asObservable()
        .map {
            [StringSection(items: $0)]
        }
        .bind(to: self.tableView.rx.items(dataSource: dataSource))
        .disposed(by: disposeBag)

    // X

    strings = ["Item 1", "Item 2", "Item 3"]
}
也推翻了这种方法:

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
    return .delete
}
但是,当我按下“编辑”按钮时,表格视图单元格没有任何变化。我看不到左边有红色的“-”按钮。我也无法向左滑动单元格以显示删除按钮


我还需要做什么才能启用编辑功能?

我想您项目中的某个地方已经将
UITableView
设置为
编辑模式。
例如,在中的代码片段之后,允许在
UITableView
中进行如下编辑:

    extension EditingExampleViewController {
    static func dataSource() -> RxTableViewSectionedAnimatedDataSource<NumberSection> {
        return RxTableViewSectionedAnimatedDataSource(
            animationConfiguration: AnimationConfiguration(insertAnimation: .top,
                                                                   reloadAnimation: .fade,
                                                                   deleteAnimation: .left),
            configureCell: { (dataSource, table, idxPath, item) in
                let cell = table.dequeueReusableCell(withIdentifier: "Cell", for: idxPath)
                cell.textLabel?.text = "\(item)"
                return cell
            },
            titleForHeaderInSection: { (ds, section) -> String? in
                return ds[section].header
            },
            canEditRowAtIndexPath: { _, _ in
                return true
            },
            canMoveRowAtIndexPath: { _, _ in
                return true
            }
        )
    }
}
扩展编辑示例视图控制器{
静态func dataSource()->rxtableviewsectionedanimatedatasource{
返回RxTableViewSectionedAnimatedDataSource(
animationConfiguration:animationConfiguration(插入动画:.top,
重新加载动画:。淡入淡出,
删除动画:。左),
configureCell:{(数据源、表、idxPath、项)位于
let cell=table.dequeueReusableCell(带有标识符:“cell”,用于:idxPath)
cell.textLabel?.text=“\(项)”
返回单元
},
titleForHeaderInSection:{(ds,section)->字符串
返回ds[section]。标头
},
canEditRowAtIndexPath:{uu,u中
返回真值
},
CANMoveRowatineXpath:{uu,u在
返回真值
}
)
}
}
我在
编辑
模式下设置
UITableView
false
,我可以向左滑动删除单元格

    extension EditingExampleViewController {
    static func dataSource() -> RxTableViewSectionedAnimatedDataSource<NumberSection> {
        return RxTableViewSectionedAnimatedDataSource(
            animationConfiguration: AnimationConfiguration(insertAnimation: .top,
                                                                   reloadAnimation: .fade,
                                                                   deleteAnimation: .left),
            configureCell: { (dataSource, table, idxPath, item) in
                let cell = table.dequeueReusableCell(withIdentifier: "Cell", for: idxPath)
                cell.textLabel?.text = "\(item)"
                return cell
            },
            titleForHeaderInSection: { (ds, section) -> String? in
                return ds[section].header
            },
            canEditRowAtIndexPath: { _, _ in
                return true
            },
            canMoveRowAtIndexPath: { _, _ in
                return true
            }
        )
    }
}