RxSwift table view with multiple custom cell types

edzio27 picture edzio27 · Aug 22, 2016 · Viewed 14.9k times · Source

I'w wonder is there any code example for RxSwift when I can use multiple custom cells inside one table view. So for example I have two section and first section has 10 cells with type CellWithImage identifier and second section has 10 cells with type CellWithVideo identifier.

All tuts and code examples which I've founded are using only one cell type, for instance RxSwiftTableViewExample

Thanks for any help

Answer

Hanryang picture Hanryang · May 27, 2019

You can set multiple custom cell without 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)