【发布时间】:2017-05-28 04:27:06
【问题描述】:
我正在使用下面的代码来摆脱最后一个静态单元格底部分隔线,它非常适合我不需要重新加载 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 单元格,唯一的方法是向情节提要中的每个 viewController 添加空白视图?将tableView.tableFooterView = UIView() 替换为viewDid/WillLayoutSubviews 会导致空屏效果。我不想为情节提要中的所有控制器添加空白视图,也许有办法以编程方式进行?
【问题讨论】:
-
你能分享一下代码吗,到目前为止你做了什么?
-
是的,当然,但没有太多可分享的
-
override func viewDidLoad() { super.viewDidLoad() tableView.tableFooterView = UIView() } 在我的带有静态单元格的 tableView 的超类中,它会删除分隔符,直到我重新加载 tableView
-
我建议您在问题中分享上述代码(编辑您的问题),也请分享 TableView 委托和数据源方法。
-
我已经尽力了,希望现在更好,非常感谢!
标签: ios objective-c swift uitableview