我正在使用RxSwift和MVVM实现一个简单的UITableView地址 . 我已经在我的视图控制器中创建了一个绑定 .
viewModel.addressList.asDriver()
.drive(tableView.rx_itemsWithCellIdentifier(reusableIdentifier, cellType: SavedAddressTableViewCell.self)) { [weak self] (row, viewModel, cell) in
self?.setUpAddressCell(cell, row: (row + 1))
}
.addDisposableTo(disposeBag)
但是,当我尝试在我的应用程序中打开页面时,我一直收到此错误 .
Maybe delegate was already set in `xib` or `storyboard` and now it's being overwritten in code.
我用Google搜索,发现我必须将tableView.delegate和tableView.dataSource设置为nil .
但是,我仍然需要一些UITableViewDataSource方法,比如
canEditRowAtIndexPath
commitEditingStyle
删除地址 .
我该如何实现呢?提前致谢 .
2 回答
在上面写这一行:
好的,我找到了解决方案 .
使用RxDataSources .
https://github.com/RxSwiftCommunity/RxDataSources
我真的不想为此使用新的pod,但我找不到替代解决方案 .
好的,我现在确实找到了替代解决方案!
使用
这个函数是ReactSwift的commitEditingStyle的包装器(误导是!),无论你在commitEditingStyle中编写什么,你现在都可以在这个函数中编写 . 对于canEditRowAtIndexPath,我总是希望返回true,这是默认的返回值,即使我没有为此编写代码,所以我根本不需要实现canEditRowAtIndexPath!