当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
如果你想移除UITableview中不需要的空间,你可以使用下面两个方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
其他回答
只需添加这个代码(Swift)。
tableView.tableFooterView = UIView()
当tableView有tableFooterView时UIKit不会创建空单元格。我们可以做个小技巧分配一个零高度的UIView对象作为tableView的页脚。
tableView.tableFooterView = UIView()
只需添加一个视图,以所需的分隔符颜色为背景色,宽度为100%,高度为1px,位置为x0 y-1到你的tableViewCell。确保tableViewCell不剪辑子视图,而应该是tableView。
所以你得到了一个绝对简单的和工作的分离只在现有的单元之间没有任何hack每个代码或IB。
注意:在垂直顶部反弹时,第一个分隔符会出现,但这应该不是问题,因为这是iOS的默认行为。
如果你想移除UITableview中不需要的空间,你可以使用下面两个方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
如果你在你的视图中有一个搜索栏(例如限制结果的数量),你还必须在shouldReloadTableForSearchString和shouldReloadTableForSearchScope中添加以下内容:
controller.searchResultsTable.footerView = [ [ UIView alloc ] initWithFrame:CGRectZero ];