我有一个 UICollectionView,我想让它显示 3 个自定义单元格。
我已阅读文档,但无法解决此问题。
我有什么遗漏的吗?
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
Run Code Online (Sandbox Code Playgroud)
我尝试将 return 1 更改为 3 以使 3 个自定义单元格出现,但它只使第一个自定义单元格出现 3 次。
我创建了一个视频并链接了下面的视频来解释我的情况。
https://www.loom.com/share/9b5802d6cc7b4f9a93c55b4cf7d435bb
编辑我使用了@Asad Farooq 方法,它似乎对我有用。我添加了如下所示的 CollectionView,现在我可以制作自定义单元格!
if(indexPath.item==0)
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DailyCollectionViewCell", for: indexPath) as! DailyCollectionViewCell
return cell
}
if(indexPath.item==1)
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WeeklyCollectionViewCell", for: indexPath) as! WeeklyCollectionViewCell
return cell
}
else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MonthlyCollectionViewCell", for: indexPath) as! MonthlyCollectionViewCell
return cell
}
}
Run Code Online (Sandbox Code Playgroud)