如果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 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屋!