Was wondering how to properly display a notification or text when there are no rows / cells found on my UICollectionViewController
and UITableViewController
. At this time I would only show a UIAlertView
, is there a better way to approach this?
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Warning!"
message:@"No rows found"
delegate:self
cancelButtonTitle:@"Logout"];
[alert show];
UICollectionView (and UITableView) has a property named backgroundView. You can create a view with a label, and just play with the hidden property of it.
I actually use this technic to show the "no rows" label and the "loading" label.
I personally use the UICollectionView
footer to show this kind of messages. I make a footer in the Story Board(Section Footer
selected in the attribute inspector of the story board) with a label with the message and then in the UICollectionViewController
:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionFooter) {
reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
if(images.count>0){
reusableview.hidden = YES;
reusableview.frame = CGRectMake(0, 0, 0, 0);
}else{
reusableview.hidden = NO;
reusableview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
}
return reusableview;
}
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