我有UICollectionView
次{2} sections
。在第一个中有一个自定义UISegmentedControl
有两个选项:“全部”和“收藏”。当我点击其中一个时,我从我的CoreData
获取数据,所以如果我点击“全部” “我从我的entity
号码1中获取数据,如果我点击”收藏“,我会从entity
号码中获取数据2.在第二个section
我有UICollectionViewCell
。当我单击UISegmentedControl
时,除了获取数据之外,我只想在第二部分重新加载数据,其中我有我的单元格,而不是所有的collectionView。我尝试使用方法reloadSections
,但我收到错误:attempt to create view animation for nil view
。我无法弄清楚原因。这是我的segmentedControl代码:
func didSelect(_ segmentIndex: Int) {
if segmentIndex == 1{
fetchDataFavourite()
collectionView?.reloadSections([0])
}else{
fetchData()
collectionView?.reloadSections([0])
}
}
答案 0 :(得分:0)
在我的情况下它缺少
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
在UICollectionViewDataSource
的实施中。