I have just started working with RxSwift and facing some challenges. I have created tableview with multiple section and able to tap and get details. However if I try to delete any particular cell, its not working. I am not sure what I am doing wrong in RxSwift. Below is my code.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, User>>(
configureCell: { (_, tv, indexPath, element) in
let cell = tv.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = string
cell.textLabel?.numberOfLines = 0
return cell
},
titleForHeaderInSection: { dataSource, sectionIndex in
return dataSource[sectionIndex].model
}
)
dataSource.canEditRowAtIndexPath = { dataSource, indexPath in
return true
}
viewModel.getUsers()
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: disposeBag)
tableView.rx
.itemSelected
.map { indexPath in
return (indexPath, dataSource[indexPath])
}
.subscribe(onNext: { pair in
print("Tapped \(pair.1) @ \(pair.0)")
})
.disposed(by: disposeBag)
tableView.rx.itemDeleted
.subscribe{
print($0)
}
.disposed(by: disposeBag)
tableView.rx
.setDelegate(self)
.disposed(by: disposeBag)
}