如果 UITableViewCells 为空,则隐藏删除分隔线 [英] Hide remove separator line if UITableViewCells are empty
问题描述
我有一个 UITableView
并且我只有 3 行,我可以看到那 3 行.问题是空的单元格:我可以在那里看到线条.我不想看到那些线条.
I have a UITableView
and I have only 3 rows in it, and I can see those 3 rows. The problem is the cells that are empty: I can see lines there. I don't want to see those lines.
知道如何删除这些行吗?
Any idea how to remove those lines?
下面是我要找的图片.
推荐答案
您可以使用以下任一代码片段来隐藏 UITableView
的标准分隔线.添加自定义分隔符的最简单方法是添加一个简单的UIView
1px 高度:
You can hide UITableView
's standard separator line by using any one of the below snippets of code.
The easiest way to add a custom separator is to add a simple UIView
of 1px height:
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 的回答,它非常简短而且也很有帮助.你也应该试试这一行,
And also check nickfalk's answer, it is very short and helpful too. And you should also try this single line,
self.tableView.tableFooterView = [[UIView alloc] init];
不确定,但它适用于我检查过的所有 iOS 版本,iOS 5 及更高版本,直到 iOS 7.
Not sure but it's working in all the version of iOS that I checked, with iOS 5 and later, up to iOS 7.
这篇关于如果 UITableViewCells 为空,则隐藏删除分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!