0

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

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

在此处输入图像描述

当我尝试删除常规单元格时,我不希望标题移动。

我在标题原型单元格上禁用了用户交互。它仍然在移动。在提交编辑风格中,我会立即返回标题原型单元格。它仍然在移动。我不知道还能做什么。请帮忙。

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
}

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

4

1 回答 1

1

更新答案:

创建一个 UIView 并将 tableViewCell 添加为子视图并返回 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

}

输出:

在此处输入图像描述

于 2016-07-27T07:18:07.357 回答