I have an UICollectionView that shows stores in a particular city. A particular city might not have any stores at all, so in that case I should update the UICollectionView to be empty. When I make nil the data parameter, the app crashes saying the data parameter cannot be nil.
How can I empty the UICollectionView? In that case, besides showing no cells at all, I'd like to show a background-image informing the user that there are no stores, or removing the collectionView all together.
any ideas?
I think you have an array with data to create yours cells.
You can add a label above your collection view and hide this label if there is cell or display this label if there is no cell.
So, when you calculate your array, add a test :
self.myLabel.hidden = (_data.count > 0);
And you have this method to return the number of cells (_data.count = 0 if there is no data)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _data.count;
}
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