我想当我的 UITableView 为空时显示图像背景。
目前,我尝试将 UIImageView 添加到包含表格的视图控制器,但 XCode 不允许这样做。
有没有好的方法呢?
您可以在表视图顶部添加图像视图或更改表视图的背景视图。
// Check if table view has any cells
int sections = [self.tableView numberOfSections];
BOOL hasRows = NO;
for (int i = 0; i < sections; i++) {
BOOL sectionHasRows = ([self.tableView numberOfRowsInSection:i] > 0) ? YES : NO;
if (sectionHasRows) {
hasRows = YES;
break;
}
}
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)