RxSwift and UIPickerView

Is there a way to bind a UIPickerView to an observable?

For example, for a UITableView I would do:

 myObservableArray.bindTo(tableView.rx.items(cellIdentifier: "Identifier", cellType: MyCustomTableViewCell.self)) { (row, title, cell) in cell.textLabel?.text = title } .disposed(by: disposeBag) 

Is there something similar for UIPickerView ?

+5
source share
1 answer

The provided data source of your collector is as follows:

 let pickerDataSource: [[String]] = [ ["asdadadad", "sffgddfg"], ["sfsdasgag", "sdfasdfasfsf", "sdsfgagagaggs"] ] 

you can implement the โ€œbindingโ€ you need as follows:

 pickerView.rx.itemSelected.subscribe(onNext: { [weak self] row, component in guard let s = self else { return } s.label.text = s.pickerDataSource[component][row] }).addDisposableTo(disposeBag) 
0
source

Source: https://habr.com/ru/post/1264358/


All Articles