Rx_itemsWithCellFactory Call Syntax

In the RxSwift example, this works:

        viewModel.rows
        .bindTo(resultsTableView.rx_itemsWithCellIdentifier("WikipediaSearchCell")) { (_, viewModel, cell: WikipediaSearchCell) in
            cell.viewModel = viewModel
        }
        .addDisposableTo(disposeBag)

How to write it using rx_itemsWithCellFactory?

+4
source share
1 answer

It took me a while to get it, and there is no google help yet. Hope this saves you a few minutes.

        viewModel.rows
        .bindTo(resultsTableView.rx_itemsWithCellFactory){
            (tv, i, vm) in
            let indexPath = NSIndexPath(forItem: i, inSection: 0)
            let cell = tv.dequeueReusableCellWithIdentifier("WikipediaSearchCell", forIndexPath: indexPath) as! WikipediaSearchCell
            cell.viewModel = vm
            return cell as UITableViewCell
        }
        .addDisposableTo(disposeBag)
+9
source

Source: https://habr.com/ru/post/1610657/


All Articles