我正在使用下面的代码来摆脱最后一个静态单元格底部分隔线,它适用于我不需要重新加载tableView的情况 . 一旦我重新加载我的tableView分隔线出现 .
只有超级VC中的代码:
override func viewDidLoad() {
super.viewDidLoad()
let footerFrame = CGRect(x: 0.0, y: 0.0, width:
tableView.frame.size.width, height: 1.0)
tableView.tableFooterView = UIView(frame: footerFrame)
}
并致电:
fileprivate func showDatePicker()
{
datePicker.setValue(UIColor.white, forKey: "textColor")
showsDatePicker = true
tableView.beginUpdates()
tableView.endUpdates()
tableView.contentInset = UIEdgeInsets(top: -20.0, left: 0.0,
bottom: 0.0, right: 0.0)
}
在我孩子的tableView(didSelectRowAt indexPath:_)中我只是用日期选择器更改单元格的高度:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard showsDatePicker else {
switch indexPath.row {
case CellIndex.withDatePicker:
return 0.0
default:
return 44.0
}
}
switch indexPath.row {
case CellIndex.withDatePicker:
return 217.0
default:
return 44.0
}
}
之后我画了分隔线!也许这是因为STATIC单元格的使用,唯一的方法是在storyboard中为每个viewController添加空白视图?将 tableView.tableFooterView = UIView()
替换为 viewDid/WillLayoutSubviews
会导致空屏幕效果 . 我不想在故事板中为我的所有控制器添加一个空白视图,也许有一种方法可以通过编程方式进行操作?
2 回答
在显示最后一个单元格之前
创建具有最小高度的页脚:
要么
我获得这个结果的方法如下,
在viewDidLoad函数中,
定义表视图的节数
在你的cellForRowAtIndexPath函数中,
这种方法对您有所帮助 .