【问题标题】:uitableview header view issueuitableview 标题视图问题
【发布时间】: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


【解决方案1】:

我检查了这里的链接Swipe to delete cell causes tableViewHeader to move with cell得到了答案。

而不是单元格返回 cell.contentview.both 问题已解决

       func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if section == 1 {
               let header = tableView.dequeueReusableCellWithIdentifier("audiocellheader")! as UITableViewCell
               return header.contentView
        }   
        else {
             return nil
        }
      }

【讨论】:

    猜你喜欢
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 2012-08-01
    • 1970-01-01
    相关资源
    最近更新 更多