0

I know there are a lot of questions about this, I looked at all of them but it doesn't fix my problem. I also commented on one of them but the question doesn't seem to be active anymore so I don't expect an answer there.

I'm trying to implement RxDataSources. See my code below:

struct ActiveOrdersSection: Equatable {
    static func == (lhs: ActiveOrdersSection, rhs: ActiveOrdersSection) -> Bool {
        return true
    }

    var header: String
    var orders: [Order]
}

extension ActiveOrdersSection: SectionModelType {
    typealias Item = Order

    var items: [Item] {
        set {
            orders = items
        }
        get {
            return orders
        }
    }

    init(original: ActiveOrdersSection, items: [Order]) {
        self = original
        self.items = items
    }
}

And the ViewController:

class MainViewController: UITableViewDelegate, UITableViewDataSource {

    var db: DisposeBag?
    var dataSource: RxTableViewSectionedReloadDataSource<ActiveOrdersSection>?
    private func setupOrderRx(_ shopId: Int64) {
        let dataSource = RxTableViewSectionedReloadDataSource<ActiveOrdersSection>(
            configureCell: { ds, tv, ip, item in
                let cell = tv.dequeueReusableCell(withIdentifier: "Cell", for: ip) as! UITableViewCell
                cell.textLabel?.text = "Item \(item.id)"
                return cell
            },

            titleForHeaderInSection: { ds, ip in
                return ds.sectionModels[ip].header
            }
        )

        self.dataSource = dataSource
        db = DisposeBag()
        let ors = OrderRxService.listAsShop(shopId, status: .active)
            .map { Observable.just($0.items) } // Convert from Observable<CollectionResponse<Order>> to Observable<Order>
            .observeOn(MainScheduler.instance)
            .bind(to: self.rxTableView.rx.items(dataSource: dataSource))
    }

}

I get Generic parameter 'Self' could not be inferred on .bind(to: self.rxTableView.rx.items(dataSource: dataSource)). I looked at the RxDataSources examples and seem to have it the same now, but I can't seem to fix this error.

Any ideas?

4

1 回答 1

1

您绑定到的 Rx 流RxTableViewSectionedReloadDataSource必须是Observable<[ActiveOrdersSection]>. 我不确切知道您在此示例中的类型是什么,因为您提供的代码还不够,但我认为通过使用.map { Observable.just($0.items) }结果流将是 type Observable<Observable<[Order]>>。尝试将其更改为: .map { [ActiveOrdersSection(header: "Your Header", orders: 0.items)] }

于 2019-03-26T12:25:06.790 回答