我在使用 RxSwift 实现 UITableView 时遇到问题。
我尝试使用以下代码将模型数组的可观察对象绑定到表项。models.bind(to: self.tableView.rx.items(cellIdentifier: "Cell", cellType: ModelTableViewCell.self
.
但是当我这样做时,会出现以下错误:Type 'inout UITableView' does not conform to protocol 'ReactiveCompatible'
我知道错误不可能是正确的,因为 NSObject 扩展了 ReactiveCompatible,所以 UITableView 也是如此。另外,我的项目代码与上显示的示例并没有真正的不同RxSwift社区 https://github.com/RxSwiftCommunity/RxDataSources
我创建了一个有错误的小示例项目。
Swift 是非常好的语言,但有时会发生编译器无法识别参数类型的情况。然后您需要显式定义参数类型。在您的情况下,您需要定义块参数的类型,请参阅代码:
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)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)