iphone - 如果 UITableview 为空显示图像

标签 iphone objective-c xcode uitableview

我现在正在 Google 上寻找 3 个小时如何删除 tableview 并在 tableview 为空(没有更多行)时显示图像。有人知道吗?我知道这是可能的,因为我在很多应用程序上都看到过。

我能找到的是:

// Check if table view has any cells
int sections = [self.tableView numberOfSections];
BOOL hasRows = NO;
for (int i = 0; i < sections; i++)
    hasRows = ([self.tableView numberOfRowsInSection:i] > 0) ? YES : NO;

if (sections == 0 || hasRows == NO)
{
    UIImage *image = [UIImage imageNamed:@"test.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    // Add image view on top of table view
    [self.tableView addSubview:imageView];

    // Set the background view of the table view
     self.tableView.backgroundView = imageView;
}

放在哪里?

谢谢!

最佳答案

如果您使用 Storyboard 只是将 View 放在 UITableView 之后

如果您的数据数组在创建时为空,只需隐藏您的 UITableView 以显示其背后的“空表” View 。

[tableView setHidden:YES];

关于iphone - 如果 UITableview 为空显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14345062/

相关文章:

ios - Xcode 8 后的 AlamofireObjectMapper 问题

iphone - UIVIEW 子类与 UITextViewDelegate

c - 在 xcode 中运行测试时,在 NSObject.h、NSObjCRuntime.h 等类中出现错误

iphone - 当用户安装了 FB 的应用程序时,iOS Facebook 连接不起作用?

iphone - NSMutableArray 中的 indexOfObject 返回垃圾值

ios - 将 UITextView 放在未定义数量的 UITableViewCell 下方?

ios - 应用程序中的状态栏消失了(Xcode iphone)

ios - 如何从 NSDate 中删除时区偏移量

ios - 在不创建属性的情况下访问私有(private)变量

ios - 如何在 iOS 7(越狱)中模拟主页按钮按下事件?