当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
如果你在你的视图中有一个搜索栏(例如限制结果的数量),你还必须在shouldReloadTableForSearchString和shouldReloadTableForSearchScope中添加以下内容:
controller.searchResultsTable.footerView = [ [ UIView alloc ] initWithFrame:CGRectZero ];
其他回答
如果你想移除UITableview中不需要的空间,你可以使用下面两个方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
界面构建器(iOS 9+)
只需将一个UIView拖到表中。在故事板中,它将位于自定义单元格下方的顶部。您可能更喜欢将其命名为“footer”。
为了清晰起见,这里显示为绿色,你可能想要清晰的颜色。
请注意,通过调整高度,您可以根据自己的喜好影响如何处理表的“底部反弹”。(高度通常为0)。
用程序来做:
斯威夫特
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.tableFooterView = UIView()
}
objective - c
iOS 6 . 1 +
- (void)viewDidLoad
{
[super viewDidLoad];
// This will remove extra separators from tableview
self.tableView.tableFooterView = [UIView new];
}
如果你愿意,
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
从iOS来看:
添加到表视图控制器…
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return CGFLOAT_MIN;
}
如果有必要……
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [UIView new];
// If you are not using ARC:
// return [[UIView new] autorelease];
}
我使用一个表视图来显示固定数量的固定高度行,所以我简单地调整了它的大小并使其不可滚动。
为了以编程方式消除UItableview底部额外的分隔行,只需写下下面两行代码,它就会从UItableview底部删除额外的分隔行。
tableView.sectionFooterHeight = 0.f;
tableView.sectionHeaderHeight = 0.f;
这招对我一直很管用,你自己试试。
在Swift中移除UITableView中空行的额外分隔行
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.yourTableview.tableFooterView = UIView()
}