私はスクロールビューで複数のコレクションビューを持っています。データが正しく表示されないという問題があります(最初のページの項目数は前回と同じです)。私は問題がコレクションビューのデータソースオブジェクトにあると思います。私はそれを読んだ:Swift:1つのビューコントローラで複数のコレクションビューの複数のデータソースを初期化する方法
collectionView.dataSource = MyDataSource() は間違っています。データソースは弱い参照であるため、作成後に元の状態になるためには強く参照する必要があります。 ViewControllerにプライベートプロパティを追加して、初期化してから問題を解決しました。
しかし、私は複数のデータセットに対してどうすればいいのですか?
pages = musicItems.count/6+1 //numberOfItems%itemsOnTheScreen
self.scrollView.delegate = self;
self.scrollView.isScrollEnabled = true
self.scrollView.isPagingEnabled = true
bounds = self.scrollView.bounds
let flowLayout = CVLayout()
for i in 0...pages-1 {
let x = bounds.width*CGFloat(i)
let y = bounds.origin.y
let width = bounds.width
let height = bounds.height
let collectionViewElement = UICollectionView(frame: CGRect(x:x,y:y,width:width,height:height), collectionViewLayout: flowLayout)
if let page = i as? Int {
collectionViewElement.register(ImageCollectionViewCell.self, forCellWithReuseIdentifier: "cell\(page)")}
var ds: CVDataSource = CVDataSource()
ds.page = i
ds.itemsCount = itemsOnThePage(currentPage: i)
collectionViewElement.delegate = ds//self
collectionViewElement.dataSource = ds//self
print("set value \(i)")
collectionViewElement.isScrollEnabled = false
collectionViewElement.backgroundColor = UIColor.white
self.scrollView.addSubview(collectionViewElement)
}
あなたの要件をよりよく理解するために、スクリーンショットをアップロードしてください。 – iDeveloper