我有以下内容 -
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
如果我 -
- 点击“删除”,上面带有参数“commit editStyle”的方法不会被调用
- 当删除出现时,向左滑动一直到 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/