ios - 在 UITableView 单元格滑动中选择“删除”,但未调用“提交编辑样式”
问题描述
我有以下 -
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")
}
当我在单元格上左滑时,“删除”选项按预期显示 - 显示 删除操作
如果我 -
- 点击删除,上面带有参数'commit editingStyle'的方法不会被调用
- 一直向左滑动到视图的左侧,而不是在出现 Delete 时停止,调用该方法。
在我看来,此方法将同时使用#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
然后是操作按钮。
简单地删除它可能/会导致问题(第一个注意到的是“下拉”在点击它外部时不会关闭)。
所以你需要编辑那个函数......可能需要做一些工作,但这是开始的地方。
推荐阅读
- python - 回复挑战 2019 中的问题“密码”
- amazon-web-services - 接口 Vpc 端点 - 日志
- java - 如何更改 java Path 对象的值?
- html - 如何在我的链接标签下获得我的链接?
- terraform - 如何使用 CODE_DEPLOY 部署控制器更新现有 ECS 服务的 desired_count?
- python - “:”在python的格式方法中做了什么?
- xml - 使用属性中的对齐信息通过 xslt 对齐 xml 元素
- excel - 使用 VBA 从表中生成列表框项
- r - 如何编写一个系数在 R 中趋于 0 的函数?
- actionscript-3 - 将十进制数转换为分数 AS3