Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxSwift table view with multiple custom cell types

Tags:

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

like image 724
edzio27 Avatar asked Aug 22 '16 12:08

edzio27


2 Answers

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) 
like image 50
Hanryang Avatar answered Dec 09 '22 19:12

Hanryang


I've managed it using RxSwiftDataSources,

it allow you to use custom cells with multi sections. I've used this code for help

like image 25
edzio27 Avatar answered Dec 09 '22 17:12

edzio27