【发布时间】:2017-05-23 03:16:10
【问题描述】:
我有一个UITableView 和一个editAction,可以通过向左滑动访问。
似乎有一个内置的UITableView 功能,如果您滑动单元格以显示编辑操作,然后点击 tableView 中的任意位置,该操作会自动滑动关闭,并调用didEndEditingRowAt通知代理编辑结束。
但是,我看到的问题是,有时,如果您向左滑动,然后在滑动后非常快速地滑动(当只有一小部分编辑操作可见并且动画正在进行时),您点击任意位置否则在屏幕上,编辑操作已关闭,但不会调用 didEndEditingRowAt!
因此,使用以下代码,我们最终使 tableView 处于编辑模式,但没有滑动打开任何视图,并且打印的最后一行是 Will Edit,确认从未调用过 didEndEditingRowAt。
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
view = tableView
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "foo")
tableView.delegate = self
tableView.dataSource = self
tableView.allowsSelectionDuringEditing = false
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .normal, title: " Remove") {(_, indexPath) in print("OK") }
return [deleteAction]
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {}
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return indexPath
}
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
print("Will edit")
}
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
print("Did end edit")
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "foo") ?? UITableViewCell()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
}
现在,这种情况只是有时会发生,而且要把握好时机有点困难,但它绝对是可重现的。
这里是整个演示的链接:https://github.com/gregkerzhner/SwipeBugDemo
我在这里做错了什么或期待错了吗?在我的真实项目中,我的代码使其他单元格淡化以专注于当前正在编辑的单元格,并且我最终处于其他单元格淡化的糟糕状态,但聚焦的单元格没有打开任何编辑操作。
【问题讨论】:
-
我很惊讶我能够在自己的项目中复制它,尽管只有十分之一的尝试。对我来说,这似乎是苹果公司的一个错误,我通常不愿意说。就个人而言,如果用户正常使用该应用程序,我认为他们不会故意这样做。
-
是的,可能与openradar.me/19411256有关
-
我想知道除了构建我自己的刷卡代码之外是否还有其他解决方法。否则这无法通过 QA!
标签: ios iphone swift uitableview