RxSwift无法转换调用结果类型'(_) - >一次性'到预期类型'(_) - >

时间:2018-02-02 09:20:20

标签: uicollectionview rx-swift uicollectionreusableview rx-cocoa rxdatasources

我正在尝试使用RxSwift将headerView添加到collectionView。

我收到此错误:

  

无法转换通话结果类型'() - >一次性'到预期类型'() - >

在这一行:

obsHeader.asObservable().bind(to: collectionView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)

我不明白如何修复它。有什么帮助吗?

我在这里发布剩下的代码:

struct SectionItemObject {
    let collectionViewRecommendations: UICollectionView
    let items: [SFCardViewModelListOfCardsProtocol]
}

struct SectionOfItems {
    var items: [Item]
}

extension SectionOfItems: SectionModelType {

    typealias Item = SectionItemObject

    init(original: SectionOfItems, items: [Item]) {
        self = original
        self.items = items
    }

    init(items: [Item]?) {
        self.items = items ?? [Item]()
    }
}

这就是我在我要求观察的方法中所写的内容。

let dataSource = RxCollectionViewSectionedReloadDataSource<SectionOfItems>(configureCell: { (datasource, collectionview, indexPath, i) -> UICollectionViewCell in
        let cell = collectionview.dequeueReusableCell(withReuseIdentifier: "CardView", for: indexPath) as! CardView
        //                self.setCell(card:card,cell:cell)
        cell.lbTitle.text = "TEST"
        return cell
    }, configureSupplementaryView: { (datasource, collectionview, kind, indexPath) -> UICollectionReusableView in
        let section = collectionview.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AddNewCardCollectionHeaderView", for: indexPath) as! AddNewCardCollectionHeaderView
        section.backgroundColor = UIColor.orange
        section.collectionViewRecommendations = self.collectionViewRecommendations
        return section
    } )

let item = SectionItemObject(collectionViewRecommendations: self.collectionViewRecommendations!, items: viewModelProtocol.searchedCards.value)
let obsHeader = Variable(SectionOfItems(items: [item]))

obsHeader.asObservable().bind(to: collectionView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)

1 个答案:

答案 0 :(得分:1)

我敢打赌,obsHeader需要输入Variable<[SectionOfItems]>

所以就这样吧

let obsHeader = Variable([SectionOfItems(items: [item])])