多个原型单元 header 在删除时移动

multiple prototype cell header moves when deleting

我有两个原型细胞。一个用于显示数据,另一个用于 header 视图。

当我尝试删除常规单元格时。 header 单元格随之移动。

我不想 header 在尝试删除常规单元格时移动。

我在 header 原型单元格上禁用了用户交互。它仍然在移动。在提交编辑风格中,我立即为 header 原型单元格执行 return。它仍然在移动。我不知道还能做什么。请帮忙。

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

    if tableView == upcomingTableView {

        if let headerCell = tableView.dequeueReusableCellWithIdentifier("headerCell") {

            headerCell.textLabel?.text = sectionNames[section]

            headerCell.detailTextLabel?.text = "Rs\(sum[section])"

            headerCell.detailTextLabel?.textColor = UIColor.blackColor()

            headerCell.backgroundColor = UIColor.lightGrayColor()

            return headerCell
        }
    }

    return nil
}

索引路径处行的单元格也是非常规则的代码。

更新答案:

创建一个 UIView 并添加 tableViewCell 作为子视图和 return UIView。

Swift中的解决方案:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    if let headerCell = tableView.dequeueReusableCellWithIdentifier("headerCell") {

        //Create an UIView programmatically
        let headerView = UIView()

        headerCell.textLabel?.text = (section == 0) ? "Apple" : "Microsoft"
        headerCell.backgroundColor = UIColor.lightGrayColor()

        //Add cell as subview to UIView
        headerView.addSubview(headerCell)

        //Return the header view
        return headerView
    }

    return nil

}

输出: