Mar*_*tyn 1 uitableview ios swift rx-swift
我使用RxSwift实现UITableView时遇到问题.
我尝试使用以下代码将一个模型数组的observable绑定到表项.
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)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2104 次 |
最近记录: |