ios - 在 UITableView 单元格滑动中选择 'Delete',但未调用 'commit editingStyle'

标签 ios swift uitableview swipe-gesture

我有以下内容 -

    class BTTableView: UITableView, UITableViewDelegate, UITableViewDataSource

使用这些方法 -

    public func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }

    public func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .delete
    }

    public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
    {
        print("editingStyle")
    }

当我在单元格上滑动时,“删除”选项按预期显示 - Delete action shown

如果我 -

  1. 点击“删除”,上面带有参数“commit editStyle”的方法不会被调用
  2. 当删除出现时,向左滑动一直到 View 的左侧而不是停止,系统会调用该方法。

在我看来,这个方法会被 #1 和 #2 调用。

有人可以帮助我理解我做错了什么吗?

编辑 - 根据 DonMag 的输入,解决了以下问题:

     override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if let hitView = super.hitTest(point, with: event) {
            let isSwipeButton = String(describing: type(of: hitView)) ==  "UISwipeActionStandardButton"
            if hitView.isKind(of: BTTableCellContentView.self)  || isSwipeButton {
                return hitView
            }
        }
        return nil;
    }

最佳答案

似乎没有调用 commit,因为该类正在覆盖 hitTest:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    if let hitView = super.hitTest(point, with: event) , hitView.isKind(of: BTTableCellContentView.self) {
        return hitView
    }
    return nil;
}

并返回nil,因为hitView是操作按钮。

简单地删除它可能会导致问题(第一个注意到的是,点击“下拉菜单”外部时不会关闭)。

所以您需要编辑该函数...可能需要一些工作,但这就是开始的地方。

关于ios - 在 UITableView 单元格滑动中选择 'Delete',但未调用 'commit editingStyle',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54696687/

相关文章:

ios - 检测 applicationWillEnterForeground 中存在哪个 View

ios - 如何使用 NSSet 填充 tableView? ( swift )

iphone - 在首次启动应用程序时呈现特定的 Storyboard / View

iphone - 如何覆盖 UILabel 的 setFrame

ios - 需要有关 shouldChangeCharactersInRange 的帮助

objective-c - 简单的Objective-C脚本打开一个URL

ios - 为什么我必须为我的编程 UIViewController 子类声明相同的必需但未实现的初始化程序(编码器 aDecoder)?

swift - MPMoviePlayerController.preparePrerollAds() 准备就绪时的通知

iOS - 新闻源结构 : does Instagram use TableViews inside of TableCells?

ios - UITableViewController : NSInternalInconsistencyException