当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
当tableView有tableFooterView时UIKit不会创建空单元格。我们可以做个小技巧分配一个零高度的UIView对象作为tableView的页脚。
tableView.tableFooterView = UIView()
其他回答
试试这个。这招对我很管用:
- (void) viewDidLoad
{
[super viewDidLoad];
// Without ARC
//self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];
// With ARC, tried on Xcode 5
self.tableView.tableFooterView = [UIView new];
}
只需添加一个视图,以所需的分隔符颜色为背景色,宽度为100%,高度为1px,位置为x0 y-1到你的tableViewCell。确保tableViewCell不剪辑子视图,而应该是tableView。
所以你得到了一个绝对简单的和工作的分离只在现有的单元之间没有任何hack每个代码或IB。
注意:在垂直顶部反弹时,第一个分隔符会出现,但这应该不是问题,因为这是iOS的默认行为。
你可以在最后添加一个空的页脚,它会隐藏空的单元格,但它也会看起来很难看:
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
迅速:
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
在Swift中移除UITableView中空行的额外分隔行
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.yourTableview.tableFooterView = UIView()
}