viewcontroller中的两个集合视图,集合视图A集合视图,而集合视图B则没有

时间:2017-09-27 10:09:03

标签: swift xcode swift3 xcode6 xcode8

所以这是代码。

func numberOfSections(in collectionView: UICollectionView) -> Int {
    if collectionView == self.recommendedGamesCollectionView {
        return 1
    } else if collectionView == self.topGamesCollectionView {
        return 1
    }
    return 0
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    if collectionView == self.recommendedGamesCollectionView {
        return 6
    } else if collectionView == self.topGamesCollectionView {
        return 6
    }
    return 0
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    if collectionView == self.recommendedGamesCollectionView {
        let cell:RecommendedCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "RecommendedCell", for: indexPath) as? RecommendedCell)!
        return cell
    } else if collectionView == self.topGamesCollectionView {
        let cell:TopGamesCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "TopGamesCell", for: indexPath) as? TopGamesCell)!
        return cell
    }

    return UICollectionViewCell()
}

时髦的猴子集合视图是唯一滚动的。底部的集合视图不是。在属性检查器中也启用了两个集合视图的滚动。它们也被设置为水平滚动和反弹。

enter image description here

0 个答案:

没有答案