所以我正在嘗試在 tableviewCell 中實作 collectionView 并且在獲取資料后出現奇怪的行為。
這是 tableViewCell:
class PortfolioPieTableViewCell: PortfolioBaseCell {
@IBOutlet weak var pageControl: UIPageControl!
@IBOutlet weak var collectionView: UICollectionView!
private var disposeBag = DisposeBag()
override class var identifier: String {
return "PortfolioPieTableViewCell"
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func prepareForReuse() {
super.prepareForReuse()
disposeBag = DisposeBag()
}
func config(viewModel: PortfolioPieTableViewViewModelCell) {
collectionView.register(UINib(nibName: "PortfolioPieCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "PortfolioPieCollectionViewCell")
viewModel.items.debug("PortfolioPieTableViewViewModelCell ??").drive(collectionView.rx.items) { collectionView, index, element in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PortfolioPieCollectionViewCell", for: IndexPath(row: index, section: 0)) as! PortfolioPieCollectionViewCell
cell.configureCell(element)
return cell
}.disposed(by: disposeBag)
viewModel.fetchData()
}
}
This is the viewModel:
final class PortfolioPieTableViewViewModelCell {
//MARK:- Output
private let _items = BehaviorRelay<[[String]]>(value: [])
lazy var items = _items.asDriver(onErrorJustReturn: []).debug(" ??")
private let positions: [[String]]
init(pieList: [[String]]) {
self.positions = pieList
}
func fetchData() {
var items = [[String]]()
positions.forEach { position in
items.append(position)
}
_items.accept(items)
}
}
這是印刷品:
021-11-08 19:53:57.830: PortfolioPieTableViewViewModelCell ?? -> isDisposed 2021-11-08 19:53:57.830: ?? -> isDisposed 2021-11-08 ViewTable 19.833:??ViewTable 19.833:??17-11-08-> isDisposed -08 19:53:57.834: ?? -> 訂閱 2021-11-08 19:53:57.835: ?? -> 事件 next([]) 2021-11-08 19:53:57.835: PortfolioPie>??EventView Next []) 2021-11-08 19:53:57.836: ?? -> Event next([["800000-402", "800000-490", "800000-436", "800000-427", "84030" ", "800000-202", "800000-271", "800000-270"]]) 2021-11-08 19:53:57.836: PortfolioPieTableViewViewModelCell ?? -> 事件 next([["80020000000 -490"、"800000-436"、"800000-427"、"800000-433"、"800000-202"、"800000-271", "800000-270"]])
如您所見,我正在獲取值但我沒有輸入驅動方法:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PortfolioPieCollectionViewCell", for: IndexPath(row: index, section: 0)) as! PortfolioPieCollectionViewCell
cell.configureCell(element)
return cell
uj5u.com熱心網友回復:
這不是 RxSwift 問題。您傳遞給的閉包collectionView.rx.items由作業系統使用,并且只有在作業系統呼叫它時才會被呼叫。如果在專案存在時沒有呼叫該閉包,那是因為作業系統不需要任何單元格來顯示。
例如,如果集合視圖的大小為零,就會發生這種情況。我建議你檢查一下這個單元格的布局。我懷疑你會在那里發現問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/354319.html
標籤:ios 迅速 合适的视图 uicollectionview rx-swift
上一篇:php加號保持零作為第一個字符
