gpt4 book ai didi

ios - 具有多个自定义单元格类型的 RxSwift TableView

转载 作者:IT王子 更新时间:2023-10-29 05:21:31 26 4
gpt4 key购买 nike

我想知道当我可以在一个表格 View 中使用多个自定义单元格时,是否有任何 RxSwift 的代码示例。例如,我有两个部分,第一部分有 10 个单元格,类型为 CellWithImage 标识符,第二部分有 10 个单元格,类型为 CellWithVideo 标识符。

我创建的所有 tuts 和代码示例都只使用一种单元格类型,例如 RxSwiftTableViewExample

感谢您的帮助

最佳答案

您可以在没有 RxDatasource 的情况下设置多个自定义单元格。

    //Register Cells as you want
tableView.register(CustomRxTableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "BasicCell")



ViewModel.data.bind(to: tableView.rx.items){(tv, row, item) -> UITableViewCell in

if row == 0 {
let cell = tv.dequeueReusableCell(withIdentifier: "BasicCell", for: IndexPath.init(row: row, section: 0))

cell.textLabel?.text = item.birthday
return cell
}else{
let cell = tv.dequeueReusableCell(withIdentifier: "Cell", for: IndexPath.init(row: row, section: 0)) as! CustomRxTableViewCell
cell.titleLb.text = item.name
return cell
}

}.disposed(by: disposeBag)

关于ios - 具有多个自定义单元格类型的 RxSwift TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39079491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com