简体   繁体   中英

How to use dataSource and delegate methods with RxSwift

I'm trying to use UIPickerView with RxSwift. Is there a way to wrap the UIPickerView dataSource and delegate methods to be used with Observables? I'm trying to do something like

dataSequence
    .bindTo(pickerView.rx_itemsWithDataSource(dataSource))

I see there is a premade library for UITableview https://github.com/RxSwiftCommunity/RxDataSources but I'm wondering if there's an easy way to generalize this for other things that require dataSource and delegate using RxSwift.

The basic RxCocoa pod which you should have imported with RxSwift in the podfile should already had this.

In case you didn't import that in your podfile, add

pod 'RxCocoa',    '~> 3.0'

Proceed then to bind the delegate like you would with a normal TableView. I didn't see any dataSource observable for UIPickerView though, so you should check that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM