这个问题在这里已经有了答案:
Eliminate extra separators below UITableView
(34 个回答)
5年前关闭。
我有一个 UITableView
并且我只有 3 行,我可以看到那 3 行。问题是空的单元格:我可以在那里看到线条。我不想看到那些线条。
知道如何删除这些行吗?
下面是我正在寻找的图像。
最佳答案
您可以使用以下任一代码片段隐藏 UITableView
的标准分隔线。
添加自定义分隔符的最简单方法是添加一个简单的 1px 高度的 UIView
:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor clearColor]; // set color as you want.
[cell.contentView addSubview:separatorLineView];
或
self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,370) style:UITableViewStylePlain];
self.tblView.delegate=self;
self.tblView.dataSource=self;
[self.view addSubview:self.tblView];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
v.backgroundColor = [UIColor clearColor];
[self.tblView setTableHeaderView:v];
[self.tblView setTableFooterView:v];
[v release];
或
- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// To "clear" the footer view
return [[UIView new] autorelease];
}
或
还要检查 nickfalk's answer ,它也很短而且很有帮助。
你也应该试试这一行,
self.tableView.tableFooterView = [[UIView alloc] init];
不确定,但它适用于我检查过的所有 iOS 版本,iOS 5 及更高版本,直到 iOS 7。
关于ios - 如果 UITableViewCells 为空,则隐藏删除分隔线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14460772/