iPhone:在普通视图表中隐藏空表单元格

时间:2010-12-03 14:03:16

标签: iphone ios uitableview

我似乎无法弄清楚如何隐藏没有数据的表格单元格。在分组视图中,每个数据只能获得一个单元格。而在普通视图中,它将单元格渲染到屏幕的底部。我确定它是可能的,因为世界时钟会这样做

3 个答案:

答案 0 :(得分:5)

要获得此世界时钟效果,我为UITableView背景设置了背景图像,并通过以下方式将表格背景颜色设置为 clearColor

UIImage *image = [UIImage imageNamed:@"background.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:self.tableView.bounds];
[self.tableView setBackgroundView:imageView];
[imageView release];
[self.tableView setBackgroundColor:[UIColor clearColor]];

为了摆脱分隔符,我已将分隔符样式更改为 none 通过

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

对于UITableViewCell,我设置了背景颜色(这里:白色):

UIView *cellBackgroundView = [[UIView alloc] init];
[cellBackgroundView setBackgroundColor:[UIColor whiteColor]];
[cell setBackgroundView:cellBackgroundView];
[cellBackgroundView release];

答案 1 :(得分:4)

无论表的类型如何,它都将填充在Interface Builder中分配给它的空间(或者任何分配的帧,等等,如果你以编程方式创建它)。

您可能想要做的是将背景设置为透明(使用“清除颜色”选项作为界面生成器中的背景颜色)并使用自定义单元格背景,这是我认为的世界时钟。< / p>

为此,只需在tableView:cellForRowAtIndexPath:方法中返回表格单元格中的背景,方法是创建一个视图,并在UITableViewCell上适当地使用setBackgroundView和setSelectedBackgroundView方法。

答案 2 :(得分:2)

Andy的

This answer是解决这个问题的最简单方法。它告诉表视图有一个页脚(大小为零)并且可以防止绘制分界线(这样可以显示空行的外观)。

相关问题