Is there a way to bind a UIPickerView
with 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
?
As a matter of fact there is, in the RxCocoa library:
Example:
let items = Observable.just([
"First Item",
"Second Item",
"Third Item"
])
items
.bind(to: pickerView.rx.itemTitles) { (row, element) in
return element
}
.disposed(by: disposeBag)
There's also:
items
.bind(to: pickerView.rx.items) { (row, element, view) in
guard let myView = view as? MyView else {
let view = MyView()
view.configure(with: element)
return view
}
myView.configure(with: element)
return myView
}
.disposed(by: disposeBag)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With