Ios 为什么在实现UITableViewRowAction时,所有节标题行都会随表格单元格一起滑动

Ios 为什么在实现UITableViewRowAction时,所有节标题行都会随表格单元格一起滑动,ios,uitableview,swift,uitableviewrowaction,Ios,Uitableview,Swift,Uitableviewrowaction,我有下面的swift代码来实现UITableViewRowAction,当我滑动一行时,该行会按预期向左滑动,但是所有的节标题行也会与表行同时向左滑动 我还提供了一个屏幕截图来显示正在发生的事情 如果我删除viewForHeader覆盖并将其替换为TitleForHeaderSection,那么我就没有问题了 覆盖viewForHeader的原因是我想在标题行中放置一个图像 override func tableView(tableView: UITableView, viewForHeader

我有下面的swift代码来实现UITableViewRowAction,当我滑动一行时,该行会按预期向左滑动,但是所有的节标题行也会与表行同时向左滑动

我还提供了一个屏幕截图来显示正在发生的事情

如果我删除viewForHeader覆盖并将其替换为TitleForHeaderSection,那么我就没有问题了

覆盖viewForHeader的原因是我想在标题行中放置一个图像

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

    let cell = tableView.dequeueReusableCellWithIdentifier("header") as UITableViewCell

    cell.textLabel?.text = instrumentGroups[section].name
    cell.imageView?.image = UIImage(named: instrumentGroups[section].name)

    return cell
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> InstrumentTableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("instrumentCell", forIndexPath: indexPath) as InstrumentTableViewCell

    cell.instrument = instrumentGroups[indexPath.section].instruments[indexPath.row]

    return cell
}

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {

    let instrument = instrumentGroups[indexPath.section].instruments[indexPath.row]

    var actions: [AnyObject] = []

    var action = UITableViewRowAction(style: .Normal, title: "Remove Watch") { (action, indexPath) -> Void in
        tableView.editing = false

        instrument.SetWatchList(false)

        self.refresh()
    }

    action.backgroundColor = UIColor.redColor()
    actions.append(action)

    return actions
}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

}

我也有同样的问题。答案很简单。
因为您使用UITableViewCell作为标题视图。请改用UILabel或UITableViewHeaderFooterView。

只需在viewForHeaderInSection函数中返回
单元格。contentView
而不是
单元格
,您的问题就会得到解决。

如果您的分区有背景色,请将其应用于
contentView
而不是单元格本身。