【发布时间】:2017-03-24 19:43:54
【问题描述】:
这是我的代码 sn-p:
class ProductCategoryCell: UITableViewCell {
@IBOutlet weak var collectionViewProducts: UICollectionView!
// other stuff...
func setProducts() {
let productsObservable = Observable.just([
Product(name: "test", price: 10.0),
Product(name: "test", price: 10.0),
Product(name: "test", price: 10.0)
])
productsObservable.bindTo(collectionViewProducts.rx.items(cellIdentifier: "ProductCell", cellType: ProductCell.self)) {
(row, element, cell) in
cell.setProduct(element)
}.disposed(by: disposeBag)
}
}
它给了我一个构建错误:
没有'items'候选产生预期的上下文结果类型'(Observable) -> (_) -> _'
在我的视图控制器中,我使用类似的代码填充表格视图:
let productsObservable = Observable.just(testProducts)
productsObservable.bindTo(tableViewProducts.rx.items(cellIdentifier: "ProductCategoryCell", cellType: ProductCategoryCell.self)) { (row, element, cell) in
cell.setCategory(category: element)
}.disposed(by: disposeBag)
此代码正常工作。我做错了什么?
【问题讨论】:
标签: swift uicollectionview rx-swift rx-cocoa