我有一个普通的UITableView,有四个部分。这些部分中只有一个具有标题视图。我正在使用viewForHeaderInSection创建一个标题。
当tableView样式为纯格式时,默认的滚动行为是:遇到某个节时,即使我只有一个节标题,并且设置了nil视图,节标题仍停留在导航栏下方,直到下一节滚动到视图中为止对于其他部分,该行为仍然出现在所有部分中。我要实现的目标是使一个部分固定在导航栏下方。
没有进入私有API的方法是否可以实现?
另一个问题,如果我将tableView样式更改为分组并将一个标头视图固定在顶部并固定在导航栏下方,是否可以实现?
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 1 {
return 68
}else {
return 0.0
}
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 1 {
let header = self.tableView.dequeueReusableHeaderFooterView(withIdentifier: sectionHeader) as? SectionHeader
return header
}else {
return nil
}
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 { // Section where you want to show header
return 44.0 // section header height
}
return 0.0 // For other sections
}