【问题标题】:Edit row action displayed on top of table view section header显示在表格视图部分标题顶部的编辑行操作
【发布时间】:2023-04-01 21:15:02
【问题描述】:

在 iOS 11 上,单元格编辑操作或滑动操作(仅适用于 iOS 11)显示在部分标题的顶部,如果表格视图样式设置为普通(未分组)。这似乎是默认功能,如果这是系统错误或者我的实现错误,我会徘徊。

我实现了一个演示应用程序,使用默认表格视图实现以及标题和编辑操作行的以下功能:

标题标题

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "Section \(section)"
    }

编辑行的操作

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let firstAction = UITableViewRowAction(style: .normal, title: "Action1", handler: {_,_ in })
        let secondAction = UITableViewRowAction(style: .destructive, title: "Action2", handler: {_,_ in })
        return [firstAction, secondAction]
    }

尾随滑动操作(仅适用于 iOS 11 的新实现):

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let action1 = UIContextualAction(style: .normal, title: "Action1", handler: {_,_,_ in })
        let action2 = UIContextualAction(style: .destructive, title: "Action2", handler: {_,_,_ in })
        return UISwipeActionsConfiguration(actions: [action1, action2])
    }

以下是编辑操作显示方式的屏幕截图

这只发生在 iOS 11 上。我曾尝试交替使用上述两种方法,但我得到了相同的结果。

你知道我应该如何解决这个问题吗?这是 iOS 11 系统错误吗?

【问题讨论】:

  • 看起来它只发生在 iOS 11.4 上。在那种情况下至少对我来说。
  • 我已经在其他版本的 iOS 上测试过,对我来说也发生在 11.2.2 上,所以我认为这是 iOS 11 的一般问题
  • 是的,刚刚在 iOS 11.3 上测试过,你是对的 @frozencure 似乎只有 iOS 11
  • 可能我们做错了什么,但到目前为止,这对我来说似乎是一个系统错误。同样的事情似乎在 iOS 9 和 iOS 10 中运行良好
  • 我自己也遇到了这个问题 :( 在 iOS 9、10 但不是 11 上工作。有解决方法的想法吗?

标签: ios swift uitableview cocoa-touch ios11


【解决方案1】:

对于遇到此问题的任何人,我通过子类化 UITableViewHeaderFooterView 类然后将 layer's zPostion 设置为 1 找到了一种解决方法,这将更改窗口视图渲染中标题的视图顺序,这为我解决了这个问题。

解决方案 1:

open class HeaderFooterView: UITableViewHeaderFooterView {

    public override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)

        if #available(iOS 11.0, *) {
            self.layer.zPosition = 1;
        }
    }
}

如果您不想继承 UITableViewHeaderFooterView 类,另一种解决方法是仅覆盖 viewForHeaderInSection 委托方法,然后在返回之前设置视图的 zPosition。

解决方案 2:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "CustomHeader") as! CustomHeader

    headerView.title = "Header title"

    if #available(iOS 11.0, *) {
         headerView.layer.zPosition = 1;
    }

    return headerView
}

【讨论】:

  • 我相信这个解决方案会触发另一个bug:滚动条会出现在section header下方,因为滚动条的zPosition是0。你可以看到bughere对应的UICollectionView,解决方案是将标题视图的 zPosition 设置回 0(这将导致此问题的错误重新出现)。
  • 是的@peco,你是对的,我可以通过出现在标题后面的滚动条来复制错误。我将尝试找到解决此问题的方法。谢谢你告诉我。
  • 嘿,我正在使用它,但这不适用于部分,它只能用于行滑动
猜你喜欢
  • 2013-02-23
  • 1970-01-01
  • 1970-01-01
  • 2018-12-26
  • 1970-01-01
  • 2023-03-10
  • 2016-05-17
  • 2012-02-06
  • 1970-01-01
相关资源
最近更新 更多