简体   繁体   English

如何使用RxSwift使用dataSource和委托方法

[英]How to use dataSource and delegate methods with RxSwift

I'm trying to use UIPickerView with RxSwift. 我正在尝试将UIPickerView与RxSwift一起使用。 Is there a way to wrap the UIPickerView dataSource and delegate methods to be used with Observables? 有没有办法包装UIPickerView数据源和委托方法与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. 我看到有一个UITableview的预制库https://github.com/RxSwiftCommunity/RxDataSources,但我想知道是否有一种简单的方法可以将其用于需要使用RxSwift的dataSource和委托的其他内容。

The basic RxCocoa pod which you should have imported with RxSwift in the podfile should already had this. 您应该在podfile中使用RxSwift导入的基本RxCocoa pod应该已经有了这个。

In case you didn't import that in your podfile, add 如果您没有在podfile中导入它,请添加

pod 'RxCocoa',    '~> 3.0'

Proceed then to bind the delegate like you would with a normal TableView. 然后继续像使用普通的TableView一样绑定委托。 I didn't see any dataSource observable for UIPickerView though, so you should check that. 我没有看到UIPickerView的任何dataSource可观察,所以你应该检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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