Ios RxDataSources`通用参数';自我';无法推断`
我知道这方面有很多问题,我看了所有的问题,但这并不能解决我的问题。我也对其中一个问题发表了评论,但这个问题似乎不再活跃,所以我不希望在那里得到答案 我正在尝试实现RxDataSources。请参见下面的我的代码:Ios RxDataSources`通用参数';自我';无法推断`,ios,swift,rx-swift,rxdatasources,Ios,Swift,Rx Swift,Rxdatasources,我知道这方面有很多问题,我看了所有的问题,但这并不能解决我的问题。我也对其中一个问题发表了评论,但这个问题似乎不再活跃,所以我不希望在那里得到答案 我正在尝试实现RxDataSources。请参见下面的我的代码: struct ActiveOrdersSection: Equatable { static func == (lhs: ActiveOrdersSection, rhs: ActiveOrdersSection) -> Bool { return tru
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
}
}
和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))
}
}
class MainViewController:UITableViewDelegate,UITableViewDataSource{
var db:DisposeBag?
var数据源:RxTableViewSectionedReloadDataSource?
专用函数setupOrderRx(uShopId:Int64){
让dataSource=RxTableViewSectionedReloadDataSource(
configureCell:{ds、tv、ip、中的项
让cell=tv.dequeueReusableCell(带有标识符:“cell”,for:ip)作为!UITableViewCell
cell.textlab?.text=“项\(项.id)”
返回单元
},
标题标题节:{ds,ip in
返回ds.sectionModels[ip]。标头
}
)
self.dataSource=数据源
db=dispebag()
让ors=OrderRxService.listAsShop(shopId,状态:。活动)
.map{Observable.just($0.items)}//从Observable转换为Observable
.observeOn(MainScheduler.instance)
.bind(到:self.rxTableView.rx.items(数据源:数据源))
}
}
无法在.bind(to:Self.rxTableView.rx.items(dataSource:dataSource))
上推断出我获取的通用参数“Self”。我查看了RxDataSources示例,现在看起来是一样的,但是我似乎无法修复这个错误
有什么想法吗?绑定到RxTableViewSectionedReloadDataSource
的Rx流必须是可观察的类型。我不知道这个示例中的类型是什么,因为您提供的代码不够,但是
我认为通过使用.map{Observable.just($0.items)}
结果流将是Observable
类型。
尝试将其更改为:
.map{[ActiveOrdersSection(标题:“您的标题”,订单:0.items)]
谢谢!我似乎没有完全理解RxDataSources的概念。这解决了我的问题。