我正在尝试在collectionview中实现tableview,但是滚动水平collectionview后,tableview数据消失了,
private func rxPopularCollectionView(){
popularCollectionView.rx.setDelegate(self).disposed(by: disposeBag)
viewModel.categoryAlliancesData.map{categories -> [CategoriesAlliancesDatum?] in
self.categoryAlliances = categories
print("Inside collectionview categories")
return categories
}
.bind(to: popularCollectionView.rx.items(cellIdentifier: "PopularCollectionViewCell", cellType: PopularCollectionViewCell.self)) { (row, category,cell) in
print("I am inside Collectionview cell")
cell.labelTitle.text = /category?.title
cell.rxTableView(viewModel : self.viewModel, item: row, categoryAlliances: self.categoryAlliances ?? [])
}.disposed(by: disposeBag)}
CollectionViewCell
var disposeBag = DisposeBag()
override func prepareForReuse() {
super.prepareForReuse()
print("Inside reuse")
disposeBag = DisposeBag()
}
func rxTableView(viewModel : StoreViewModel, item: Int, categoryAlliances : [CategoriesAlliancesDatum?]){
print("Inside rxtableview")
disposeBag = DisposeBag()
DispatchQueue.main.async {
self.tableView.reloadData()
}
tableView.rx.setDelegate(self).disposed(by: disposeBag)
viewModel.alliances
.map{alliances -> [AlliancesDatum] in
let categoryAlliances = categoryAlliances[item]?.allianceID.map{alliances["\($0)"]}
print("Inside alliances")
return categoryAlliances as! [AlliancesDatum]
}
.bind(to:
self.tableView.rx.items(cellIdentifier: "PopularTableViewCell", cellType: PopularTableViewCell.self)){ (row, alliance, tableCell) in
print("I am inside Tableview cell")
tableCell.imageViewPopular.downloadImage(urlString: /alliance.thumbnail)
tableCell.labelTitle.text = /alliance.name
tableCell.labelDescription.text = /alliance.shortDescription
}.disposed(by: disposeBag)
}
Horizontal CollectionView已填充,但tableview未填充。 每次滚动collectionview时,都会调用rxTableView()函数。 问题在于tableview的rxswift绑定方法,没有被调用。