I have a UICollectionView
with 2 sections
. In the first one there is a custom UISegmentedControl
with two options: "All" and "Favourite".When I click one of them, I fetch the data from my CoreData
, so if I click "All" I fetch data from my entity
number 1, if I click "Favourite" I fetch data from my entity
number 2. In the second section
I have my UICollectionViewCell
. When I click the UISegmentedControl
, in addition to fetch the data I want to reload the data only in the second section,where I have my cells, and not in all the collectionView. I tried to use the method reloadSections
but I get an error: attempt to create view animation for nil view
.I can't figure out why.This is my code for the segmentedControl:
func didSelect(_ segmentIndex: Int) {
if segmentIndex == 1{
fetchDataFavourite()
collectionView?.reloadSections([0])
}else{
fetchData()
collectionView?.reloadSections([0])
}
}
in my case it was missing
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
in my implementation of UICollectionViewDataSource
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With