不同单元格CollectionView rxswift

问题描述 投票:0回答:1

晚上好。请告诉我我需要进行这样的实施有:CollectionViewRxswift单元格的最大数量为6如果某个数组中的元素少于6个,则第一个单元格将填充一种类型(按数组中元素的数量),其余单元格将填充其他类型。

collectionView.register(UINib(nibName: "PhotoCollectionCell", bundle: nil), forCellWithReuseIdentifier: "PhotoCell")
collectionView.register(UINib(nibName: "EmptyCollectionCell", bundle: nil), forCellWithReuseIdentifier: "EmptyCell")
uicollectionviewcell rx-cocoa
1个回答
0
投票

请从RxCocoa的collectionView.rx.items中检查UICollectionView+Rx.swift这是代码本身的示例]

   let items = Observable.just([
             1,
             2,
             3
         ])

         items
         .bind(to: collectionView.rx.items) { (collectionView, row, element) in
            let indexPath = IndexPath(row: row, section: 0)
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! NumberCell
             cell.value?.text = "\(element) @ \(row)"
             return cell
         }
         .disposed(by: disposeBag)

您可以根据行的索引或数据类型使想要的任何单元格出队,就像我们在DataSource中所做的那样。>

© www.soinside.com 2019 - 2024. All rights reserved.