【发布时间】:2017-09-21 13:27:55
【问题描述】:
我在使用 iOS 11 SDK 时遇到了一个非常奇怪的问题。
在使用滑动手势删除单元格后,在 iOS 11 设备和模拟器上将 UITableView 的 editing 标志设置为 false 时,设置后的下一行仍保持为 true。
在 iOS 10 设备和低于标志的情况下,将 correclty 设置为 false。
请看一下这个简短的例子。
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as UITableViewCell!
return cell
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
tableView.deleteRows(at: [indexPath], with: .fade)
endEditingMode()
}
}
func endEditingMode() {
tableView.setEditing(false, animated: true)
// Here we expect `isEditing = false` since it is set the line before but it is still `true` on iOS 11 devices
// On <= iOS 10 devices however its `false`
print(tableView.isEditing)
}
任何人遇到类似的问题,可能知道如何解决这个问题? 我已经为苹果创建了一个雷达。
【问题讨论】:
-
这是 UITableViewController 还是添加到 UIViewController 的表视图?表格最初是如何设置为编辑模式的?
-
它是一个添加到 UIViewController 的 tableView
-
还有,表格最初是如何设置为编辑模式的?
-
抱歉错过了那个。当我们使用滑动删除功能时,编辑设置为 true。
-
嗯。如果你在
setEditing之后将一个块分派到主队列并检查块内的tableView.isEditing怎么办?我的假设是表格视图结束编辑,只是不同步。
标签: ios swift uitableview swift3 ios11