Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No rows found" when there's no are row /cells for UICollectionView and UITableView

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];
like image 314
gdubs Avatar asked Oct 01 '13 13:10

gdubs


2 Answers

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.

like image 197
tal952 Avatar answered Oct 06 '22 00:10

tal952


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;
}
like image 37
kahlo Avatar answered Oct 05 '22 23:10

kahlo