两个不同的集合视图获取另一个的项目计数

时间:2018-03-04 18:16:46

标签: ios swift uicollectionview

我有一个带有2个不同阵列的应用程序,通常有2个不同的项目计数。由于某种原因,第一个集合视图获取第二个集合视图的项目计数,除非我摆脱第二个集合视图。

我的代码:



<script src="https://pastebin.com/embed_js/NAtgb3kp"></script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

步骤:  1.说你的收藏是

var albumsViewCollectionView, songsViewCollectionView : UICollectionView!
  1. 注册2个集合视图的nib文件

  2. 您的collectionview数据源方法

     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()
    
    }