当没有UICollectionView和UITableView的行/单元格时,"找不到行"

gdu*_*ubs 5 objective-c uitableview ios uicollectionview

想知道如果在我UICollectionViewController和我的网站上找不到行/单元格时如何正确显示通知或文本UITableViewController.在这个时候我只会展示一个UIAlertView,有没有更好的方法来解决这个问题?

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Warning!" 
message:@"No rows found" 
delegate:self
cancelButtonTitle:@"Logout"];

[alert show];
Run Code Online (Sandbox Code Playgroud)

tal*_*952 13

UICollectionView(和UITableView)有一个名为backgroundView的属性.您可以使用标签创建视图,并只使用其隐藏属性.

我实际上使用这个技术来显示"无行"标签和"加载"标签.


kah*_*hlo 7

我个人使用UICollectionView页脚来显示这种消息.我在故事板(Section Footer在故事板的属性检查器中选择)中打了一个页脚,带有带消息的标签,然后在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;
}
Run Code Online (Sandbox Code Playgroud)