gpt4 book ai didi

swift - UICollectionView 尝试为 nil View 创建 View 动画

转载 作者:搜寻专家 更新时间:2023-11-01 05:35:51 25 4
gpt4 key购买 nike

我有一个包含 2 个 sectionsUICollectionView。在第一个中有一个自定义的 UISegmentedControl,它有两个选项:“All”和“Favourite”。当我点击其中一个时,我从我的 CoreData 中获取数据,因此,如果我单击“全部”,我会从我的 entity 编号 1 中获取数据,如果我单击“Favourite”,我会从我的 entity 编号 2 中获取数据。在第二个 section 我有我的 UICollectionViewCell。当我单击 UISegmentedControl 时,除了获取数据外,我只想在第二部分重新加载数据,我有我的单元格,而不是在所有 collectionView 中。我尝试使用方法 reloadSections 但出现错误:attempt to create view animation for nil view。我不明白为什么。这是我的代码分段控制:

func didSelect(_ segmentIndex: Int) {
if segmentIndex == 1{
fetchDataFavourite()
collectionView?.reloadSections([0])
}else{
fetchData()
collectionView?.reloadSections([0])
}
}

最佳答案

在我的例子中它丢失了

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

在我的 UICollectionViewDataSource 实现中。

关于swift - UICollectionView 尝试为 nil View 创建 View 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40426792/

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