问题
just like UITableView
items.bindTo(tableView.rx.items(cellIdentifier: "cellIdentifier", cellType: AttentionTableViewCell.self)){(row,dic,cell) in
cell.configueCell(with: dic)
}.addDisposableTo(dispose)
回答1:
Maybe you just have to update your RxSwift library version. It looks like pretty much the same as UI{Table|Collection}View rx bindings. Supposing you have a data source like:
let items: Observable<[String]> = Observable.of(["Row1", "Row2", "Row3"])
To populate your UIPickerView:
items.bind(to: yourPickerView.rx.itemTitles) { (row, element) in
return element
}
.disposed(by: disposeBag)
To handle selected items:
yourPickerView.rx.itemSelected
.subscribe { (event) in
switch event {
case .next(let selected):
print("You selected #\(selected.row)")
default:
break
}
}
.disposed(by: disposeBag)
回答2:
Swift4 example
Observable.just(["Yes", "No", "Maybe"])
.bind(to: picker.rx.itemTitles) { _, item in
return "\(item)"
}
.disposed(by: disposeBag)
picker.rx.itemSelected
.subscribe(onNext: { (row, value) in
NSLog("selected: \(row)")
})
.disposed(by: disposeBag)
回答3:
Provided data source of your picker looks like this:
let pickerDataSource: [[String]] = [ ["asdadadad", "sffgddfg"],
["sfsdasgag", "sdfasdfasfsf", "sdsfgagagaggs"] ]
you could implement 'binding' in this way:
pickerView.rx.itemSelected.subscribe(onNext: {[weak self](row,component) in
guard let s = self else { return }
s.label.text = s.pickerDataSource[component][row]
}).disposed(by: disposeBag)
来源:https://stackoverflow.com/questions/42108714/how-to-realize-uipickerview-with-rxswift