gpt4 book ai didi

ios - 重新加载表格 View 后出现最后一个静态单元格分隔线

转载 作者:行者123 更新时间:2023-11-28 06:19:09 24 4
gpt4 key购买 nike

我正在使用下面的代码来摆脱最后一个静态单元格底部分隔线,它非常适合我不需要重新加载 tableView 的情况。一旦我重新加载我的 tableView 分隔线就会出现。

只有 super 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)
}

在我 child 的 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 添加空白 View ?将 tableView.tableFooterView = UIView() 替换为 viewDid/WillLayoutSubviews 会导致空屏效果。我不想向 Storyboard 中的所有 Controller 添加空白 View ,也许有办法以编程方式进行?

最佳答案

在显示最后一个单元格之前。

if indexPath.row == Your_last_Cell {

cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0);

}

创建最小高度的页脚:

func tableView(_ tableView: UITableView, 
heightForFooterInSection section: Int) -> CGFloat{

// This will create a "invisible" footer
return 0.01f; //CGFLOAT_MIN
}

func tableView(_ tableView: UITableView, 
viewForFooterInSection section: Int) -> UIView?{

UIView(frame: CGRectZero)

}

关于ios - 重新加载表格 View 后出现最后一个静态单元格分隔线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44223810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com