I use Pickerview with Rx and i would like to know how you can change view of the selected row with a custom view. i tried on a picker view without RX it works. But the same with Rx and Custom Adapter don't work. Do you have an idea to do this ?
Thanks for your answers :
For example without Rxswift :
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let customView = LimitItemPickerView(frame: CGRect.zero)
if pickerView.selectedRow(inComponent: component) == row {
customView.selected()
}
return customView
}
My implementation :
final class `PickerViewViewAdapter: NSObject, UIPickerViewDataSource, UIPickerViewDelegate, RxPickerViewDataSourceType, SectionedViewDataSourceType {
typealias Element = [MyMODEL]
private var items: [MyMODEL] = []
func model(at indexPath: IndexPath) throws -> Any {
return items[indexPath.row]
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return items.count
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 80.0
}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let customView = MyCustomView(frame: CGRect.zero, model: items[row])
return customView
}
func pickerView(_ pickerView: UIPickerView, observedEvent: Event<Element>) {
UIBindingObserver(UIElement: self) { (adapter, items) in
adapter.items = items
pickerView.reloadAllComponents()
}.on(observedEvent)
}
}`
To use this :
let input = MYVIEWMODEL.Input(param1: key,
param2: key2,
param3: key3)
let output = myViewModel.transform(input: input)
output.limitsAvailable
.drive(limitPickerView.rx.items(adapter: PickerViewViewAdapter()))
.disposed(by: disposeBag)