1

The CollectionView cells' separators are not appearing when I populate the Collection View using RxSwift. I'm using RxDataSources instead of the class functions. I believe the function drawSeparatorIfNeeded isn't being called somewhere along the way, is there any workaround for this?

Collection View preparation:

private func prepareCollectionView() {
  styler.cellStyle = .card
  styler.separatorLineHeight = 3.0
  styler.separatorColor = UIColor(hex: "#eeeeee")
  styler.shouldHideSeparators = false
  collectionView?.backgroundColor = UIColor(hex: "#eeeeee")
  collectionView?.register(MDCCollectionViewTextCell.self, forCellWithReuseIdentifier: "eventCell")

  collectionView?.translatesAutoresizingMaskIntoConstraints = false

  collectionView?.topAnchor.constraint(equalTo: navigationBar.bottomAnchor).isActive = true
  collectionView?.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
  collectionView?.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
  collectionView?.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true

  collectionView?.layoutIfNeeded()
}

Cell configuration:

dataSource.configureCell = { _, collectionView, indexPath, model in
  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "eventCell", for: indexPath) as! MDCCollectionViewTextCell
  cell.textLabel?.text = model
  cell.backgroundColor = .white
  return cell
}

Cell binding:

Observable.just(sections)
  .bindTo(collectionView!.rx.items(dataSource: dataSource))
  .addDisposableTo(disposeBag)

Inspecting the CollectionView in Reveal shows that the separator UIImageView has a height of 0, but when I use vanilla DataSource methods, it works as expected.

Ahmad
  • 603
  • 1
  • 8
  • 17

0 Answers0