如何解决RxSwift TableView具有滑动动作
我在RxSwift
框架中使用RxDataSources
来建立表格视图:
let dataSource = RxTableViewSectionedAnimatedDataSource<AnimatableSectionModel<String,String>>(configureCell: { _,tableView,indexPath,item -> UITableViewCell in
let cell = tableView.dequeueReusableCellwithIdentifier: "TestCell",for: indexPath)
cell.configure()
return cell
})
vm.cellViewModels
.map({ [AnimatableSectionModel(model: "",items: $0)] })
.bind(to: _view.tableView.rx.items(dataSource: dataSource))
.disposed(by: bag)
我正在尝试让UISwipeActionsConfiguration
在UITableViewDelegate
中工作,并将委托设置为:
tableView.rx.setDelegate(self).disposed(by: bag)
同时将委托方法设置为:
extension UIViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView,trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .normal,title: nil) { action,view,completion in
}
action.image = Images.shared.logo.resized(to: CGSize(width: 24,height: 24)).tintWithColor(.darkGray).withRenderingMode(.alwaysOriginal)
action.backgroundColor = .clear
let configuration = UISwipeActionsConfiguration(actions: [action])
configuration.performsFirstActionWithFullSwipe = false
return configuration
}
func tableView(_ tableView: UITableView,viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x: 0,y: 0,width: tableView.bounds.size.width,height: 20))
headerView.backgroundColor = UIColor.red
return headerView
}
}
标题将被调用并按预期工作,这意味着委托应设置为正确。
在不使用RxSwift的情况下执行此操作可进行滑动操作。
有人知道如何让trailingSwipeActionsConfigurationForRowAt
与RxDatasources一起工作,因为我只能让viewForHeaderInSection
与RxDatasources合作?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。