1

I created custom collectionViewCell to binding data from an obsersable to custom CollectionViewCell. I successfully bind data to a custom TableViewCell but I can't show the contents of data to custom collection view cell. Is there a problem with Rx binding with custom collection view data source?

It's my custom collection view cell:

class MovieItemCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var titleLabel: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    func bind(_ viewModel: MovieItemViewModel) {
        debugPrint("bind")
        titleLabel.text = viewModel.title
    }
}

Here's how I binding: (The following code worked completely for a tableViewCell but it does not work for collectionViewCell. By the way, the debugger do not enter to bind methods in collectionViewCell)

output.movies.drive(
    topRatedMoviesCollectionView
    .rx.items(cellIdentifier: MovieItemCollectionViewCell.reuseID,
                    cellType: MovieItemCollectionViewCell.self)) {_, viewModel, cell in
                        cell.bind(viewModel)
}.disposed(by: disposeBag)

enter image description here

mathema
  • 939
  • 11
  • 22

1 Answers1

1

The code you posted is fine and has nothing to do with the problem you are having.

If "the debugger do not enter to bind methods in collectionViewCell" then it is likely that your movies observable never emitted any values.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • Yes, you are right. I've tried tableView with working response. Collection's view's data source do not emit anything. I changed another data source with other and it bind the data immediately. Thank you so much. – mathema Jul 28 '19 at 12:12