当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
Uitableview额外的分隔线隐藏额外的分隔线隐藏在swift 3.0
self.tbltableView.tableFooterView = UIView(frame: .zero)
其他回答
我想扩展一下我的回答:
简单地添加高度为0的页脚就可以了。(在SDK 4.2, 4.4.1上测试)
- (void) addFooter
{
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
[self.myTableView setTableFooterView:v];
}
或者更简单——在你设置tableview的地方,添加这一行:
//change height value if extra space is needed at the bottom.
[_tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]];
或者更简单——简单地删除任何分隔符:
[_tableView setTableFooterView:[UIView new]];
再次感谢wkw:)
我知道这个问题已经被接受的答案,但我在这里放了不同的方法,如何隐藏额外的分隔线UITableView。
您可以隐藏tableView的标准分隔线,并在每个单元格的顶部添加您的自定义行。
更新:
添加自定义分隔符最简单的方法是添加高度为1px的简单UIView:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor grayColor]; /// may be here is clearColor;
[cell.contentView addSubview:separatorLineView];
OR
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];
OR
- (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];
}
或 我喜欢的最好最简单的方式就是
self.tableView.tableFooterView = [[UIView alloc] init];
试试其中任何一种;
当tableView有tableFooterView时UIKit不会创建空单元格。我们可以做个小技巧分配一个零高度的UIView对象作为tableView的页脚。
tableView.tableFooterView = UIView()
你可以在最后添加一个空的页脚,它会隐藏空的单元格,但它也会看起来很难看:
tableView.tableFooterView = UIView()
有一个更好的方法:在表格视图的末尾添加1点线作为页脚,空单元格也将不再显示。
let footerView = UIView()
footerView.frame = CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1)
footerView.backgroundColor = tableView.separatorColor
tableView.tableFooterView = footerView
如果你想移除UITableview中不需要的空间,你可以使用下面两个方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}