我有一个2个不同阵列的应用程序,通常有2个不同的项目计数。由于某种原因,第一个集合视图获取第二个集合视图的项目计数,除非我摆脱第二个集合视图。
我的代码:
<script src="https://pastebin.com/embed_js/NAtgb3kp"></script>
步骤:1。说你的收藏品
var albumsViewCollectionView, songsViewCollectionView : UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionview == albumsViewCollectionView {
return albumCount
}
else if collectionview == songsViewCollectionView {
return songsCount
}
return 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == albumsViewCollectionView {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AlbumsViewCollectionView", for: indexPath) as! AlbumsViewCollectionView
return cell
}
else if collectionView == songsViewCollectionView {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SongsViewCollectionView", for: indexPath) as! SongsViewCollectionView
return cell
}
return UICollectionViewCell()
}