UICollectionView尝试为nil视图创建视图动画

时间:2016-11-04 15:47:53

标签: swift

我有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])
    }
}

1 个答案:

答案 0 :(得分:0)

在我的情况下它缺少

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

UICollectionViewDataSource的实施中。