[英]How can l add cells to UICollectionView with SwiftRx?
我的任務是使用 SwiftRx 和 MVVM 模式將帶有多個單元格的 UICollectionView 添加到 UITableView 的單元格中。
我將空的 collectionView 添加到 tableView,但我不知道如何使用 SwiftRx 向其中添加一些單元格。
這是我的 CollectionCellView(我還有一種布局方法):
private(set) var bag = DisposeBag()
private let viewModel: SocialMediaCellViewModel
private let image: UIImageView = {
let img = UIImageView()
img.image = UIImage(named: "plusSocialMedia")
return img
}()
private let telegramButton: SocialMediaButton = {
let bt = SocialMediaButton()
bt.setImage(SocialMedia.telegram.icon, for: .normal)
return bt
}()
如果你能幫我弄清楚我必須在我的 ViewModel 中寫什么,以及如何在 CollectionCellView 中正確編寫 bindViewModel() 方法,那將是太棒了!
該庫有一個如何在 RxCocoa/iOS/UICollectionView+Rx.swift 處執行此操作的示例
/**
Binds sequences of elements to collection view items.
- parameter source: Observable sequence of items.
- parameter cellFactory: Transform between sequence elements and view cells.
- returns: Disposable object that can be used to unbind.
Example
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)
*/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.