gpt4 book ai didi

swift - 一页中的两个collectionView具有不同的数据

转载 作者:行者123 更新时间:2023-11-30 11:33:13 27 4
gpt4 key购买 nike

嗨,我在主页中有两个 Collection View ,如何处理这两个 Collection View 。 enter image description here

如何在函数“NumberIteminSection”和“cellForItemAtIndex”中处理两个collectionView,我不知道在一个函数中处理两个collectionView?如果有更好的方法请告诉我

最佳答案

您还可以使用标签处理多个 Collection View 。您可以为每个 Collectionview 赋予不同的标签值。

从 Storyboard的属性检查器字段分配不同的标签值,如下图所示。

enter image description here

然后在委托(delegate)或数据源方法中,您可以检查如下所示的条件。

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView.tag == 1{
return 20
}else{
return 10
}
}

希望这对您有帮助。

关于swift - 一页中的两个collectionView具有不同的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50029645/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com