简体   繁体   English

RxSwift,RxCocoa和UITableview

[英]RxSwift, RxCocoa and UITableview

I have a problem with implementing a UITableView using RxSwift. 我在使用RxSwift实现UITableView时遇到问题。

I tried to bind an observable of an array of models to the table items with the following code. 我尝试使用以下代码将可观察的模型数组绑定到表项。 models.bind(to: self.tableView.rx.items(cellIdentifier: "Cell", cellType: ModelTableViewCell.self . models.bind(to: self.tableView.rx.items(cellIdentifier: "Cell", cellType: ModelTableViewCell.self

But when I do it gives me the following error: Type 'inout UITableView' does not conform to protocol 'ReactiveCompatible' and I know the error can't be right because NSObject extends ReactiveCompatible so UITableView also does. 但是,当我这样做时,会出现以下错误:输入Type 'inout UITableView' does not conform to protocol 'ReactiveCompatible'并且我知道该错误可能不正确,因为NSObject扩展了ReactiveCompatible,所以UITableView也可以。 Also, my project code isn't really different than the examples shown on RxSwiftCommunity 另外,我的项目代码与RxSwiftCommunity上显示的示例并没有什么不同

I created a small example project that has the error. 我创建了一个有错误的小示例项目。

[显示错误的示例代码(图片)]

Swift is quite good language but sometimes happens moments when compiler couldn't recognize the type of parameters. Swift是一种非常不错的语言,但是有时会在编译器无法识别参数类型时发生。 Then you need to explicit define a type of arguments. 然后,您需要显式定义参数的类型。 In your case you need to define the type of block arguments, see the code: 在您的情况下,您需要定义块参数的类型,请参见代码:

func bindRx(viewModel: ViewModel) {
    viewModel.models.bind(to: tableView.rx.items(cellIdentifier: ModelTableViewCell.ReuseIdentifier,
                                                 cellType: ModelTableViewCell.self)) { (_, model: Model, cell: ModelTableViewCell) in
        cell.textLabel?.text = model.name
    }
    .addDisposableTo(disposeBag)
}

在此处输入图片说明

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

相关问题 处理UITableView绑定中的连接错误(Moya,RxSwift,RxCocoa) - Handle Connection Error in UITableView Binding (Moya, RxSwift, RxCocoa) 使用RxSwift和RxCocoa绑定模型并更新单元格 - Bind model and update cell with RxSwift and RxCocoa 为什么`NotificationCenter + Rx`位于RxCocoa中而不是RxSwift中 - Why `NotificationCenter+Rx` is in RxCocoa not RxSwift 在RxCocoa / RxSwift中,如何观察BehaviorRelay &lt;[object]&gt;数组大小已更改 - In RxCocoa/RxSwift, how to observe BehaviorRelay<[object]> array size changed 带有 RxCocoa 的 UITableView 没有正确观察 contentOffset 属性 - UITableView with RxCocoa is not observing correctly to contentOffset property 如何测试RxSwift变量和RxCocoa Observable之间的UI绑定? - How to test the UI Binding between RxSwift Variable and RxCocoa Observable? 当委托字段不称为`delegate`时实现`DelegateProxy`(RxSwift / RxCocoa) - Implementing `DelegateProxy` (RxSwift/RxCocoa) when delegate field is not called `delegate` 使用RxSwift和RXCocoa验证按钮单击时的所有文本字段 - Validate all textfield on button click using RxSwift and RXCocoa RxSwift和UICollectionView,UITableView - RxSwift and UICollectionView, UITableView RxSwift - 映射UITableView的contentOffset - RxSwift - mapping contentOffset of UITableView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM