[英]Handle Connection Error in UITableView Binding (Moya, RxSwift, RxCocoa)
[英]RxSwift, RxCocoa and UITableview
我在使用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也可以。 另外,我的项目代码与RxSwiftCommunity上显示的示例并没有什么不同
我创建了一个有错误的小示例项目。
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.