我现在在谷歌上找了 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/