【发布时间】:2016-03-11 08:06:47
【问题描述】:
我创建了一个 tableview,我有 2 个部分。在第二部分我需要一个标题。所以我像下面那样做了。
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 1 {
return 40
}
return 0
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 1 {
let header = tableView.dequeueReusableCellWithIdentifier("audiocellheader")! as UITableViewCell
return header
}
else {
return nil
}
}
当我重新加载部分时遇到问题。标题消失了。如果我执行 tableview.reload 它的工作正常。会有什么问题?当我删除单元格中的项目时,我也遇到了问题。图片如下。
header 获得与编辑行相同的移动。
【问题讨论】:
-
你是否正确设置了 heightforheader?
-
你不想使用
dequeueReusableHeaderFooterViewWithIdentifier吗? -
@kiran 这与高度无关。当我添加条目或删除时重新加载该部分时,视图消失了。
-
@Tim 让我检查一下 dequeueReusableHeaderFooterViewWithIdentifier
-
@TimVermeulen 我收到此错误 UITableViewHeaderFooterView 已被弃用。请改用 contentView.backgroundColor。
标签: ios swift uitableview