![](/img/trans.png)
[英]RxSwift: Ambiguous reference to member 'items(cellIdentifier:cellType:)'
[英]Ambiguous reference to member 'items(cellIdentifier:celltype:)' using RxSwift and RxRealm
我在ViewController中有一个CollectionView,并且试图从Realm获取对象列表,并使用RxSwift将其绑定到CollectionView。
问题是我遇到了错误:
“对成员'items(cellIdentifier:celltype :)的含糊不清的引用”
在这行中:.bind(至:collection.rx.items(cellIdentifier ...)
这是代码:
import UIKit
import RxRealm
import RxSwift
import RxCocoa
class MyListViewController: UIViewController {
var myList: MyList?
private var collection: UICollectionView?
{...}
private func loadMyList() {
let myList = retrieveMyListFromDb()
guard
let list = myList,
let collection = collection
else { return }
let disposeBag = DisposeBag()
Observable.from(list)
.bind(
to: collection.rx.items(
cellIdentifier: HomeMovieCollectionViewCell.identifier,
cellType: HomeMovieCollectionViewCell.self)
) { (row, element, cell) in
}
.disposed(by: disposeBag)
}
private func retrieveMyListFromDb() -> MyList? {
return RealmManager().objects(MyList.self)?.filter {
$0.userId == 0
}.first
}
这是MyList代码:
import Foundation
import Realm
import RealmSwift
@objcMembers
class MyList: Object {
dynamic var userId: Int = 0
var movies = List<Movie>()
public override static func primaryKey() -> String? { return "userId" }
}
多亏了用户Daniel T.的帮助,我才意识到问题是集合视图的rx.items函数需要一个项数组或一个列表,并且我将其与对象一起使用。 我遇到的错误并不能描述所有发生的事情。
解决方案是
Observable.collection(from: list.movies)
.bind(to: collection.rx.items(
cellIdentifier: HomeMovieCollectionViewCell.identifier,
cellType: HomeMovieCollectionViewCell.self)
) { (row, element, cell) in
}
.disposed(by: disposeBag)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.