我想知道是否有代码示例RxSwift
当我可以在一个表视图中使用多个自定义单元格。因此,例如,我有两个部分,第一部分有10个单元,类型为CellWithImage
标识符,第二部分有10个单元,类型为CellWithVideo
标识符。RxSwift表视图与多个自定义单元格类型
我已经成立仅使用一种细胞类型,例如RxSwiftTableViewExample
感谢所有帮助
我想知道是否有代码示例RxSwift
当我可以在一个表视图中使用多个自定义单元格。因此,例如,我有两个部分,第一部分有10个单元,类型为CellWithImage
标识符,第二部分有10个单元,类型为CellWithVideo
标识符。RxSwift表视图与多个自定义单元格类型
我已经成立仅使用一种细胞类型,例如RxSwiftTableViewExample
感谢所有帮助
我一直在使用RxSwiftDataSources管理其所有TUTS和代码示例,
它允许您可以使用多节的自定义单元格。
如果有人有兴趣,这是我的实施。我有一个游戏列表的应用程序。根据游戏是否完成或仍然在使用我使用不同的单元格。这里是我的代码:
在视图模型,我有比赛的名单,它们分割成成品/正在进行那些和他们在ViewController中映射到SectionModel
let gameSections = PublishSubject<[SectionModel<String, Game>]>()
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Game>>()
...
self.games.asObservable().map {[weak self] (games: [Game]) -> [SectionModel<String, Game>] in
guard let safeSelf = self else {return []}
safeSelf.ongoingGames = games.filter({$0.status != .finished})
safeSelf.finishedGames = games.filter({$0.status == .finished})
return [SectionModel(model: "Ongoing", items: safeSelf.ongoingGames), SectionModel(model: "Finished", items: safeSelf.finishedGames)]
}.bindTo(gameSections).addDisposableTo(bag)
然后,我结合我的部分,以我的tableview ,并使用不同的单元格。请注意,我可以使用indexPath来获取正确的单元格而不是状态。
vm.gameSections.asObservable().bindTo(tableView.rx.items(dataSource: vm.dataSource)).addDisposableTo(bag)
vm.dataSource.configureCell = {[weak self] (ds, tv, ip, item) -> UITableViewCell in
if item.status == .finished {
let cell = tv.dequeueReusableCell(withIdentifier: "FinishedGameCell", for: ip) as! FinishedGameCell
cell.nameLabel.text = item.opponent.shortName
return cell
} else {
let cell = tv.dequeueReusableCell(withIdentifier: "OnGoingGameCell", for: ip) as! OnGoingGameCell
cell.titleLabel.text = item.opponent.shortName
return cell
}
}
你可以分享代码你如何实现这一点毕竟? – nburk