iOS 11 UITableView isEditing 标志未正确设置

Pat*_*tar 6 uitableview ios swift swift3 ios11

我在使用 iOS 11 SDK 时遇到了一个非常奇怪的问题。当editing在 iOS 11 设备和模拟器上将 UITableView 的标志设置为false使用滑动手势删除单元格后,它仍然保留true在设置后的下一行。在 iOS 10 及以下版本的设备上,该标志被正确设置为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)
}
Run Code Online (Sandbox Code Playgroud)

任何人遇到类似的问题并且可能知道如何解决这个问题?我已经为苹果创建了一个雷达。

Sob*_*man 5

我遇到了类似的问题,并尝试通过延迟调度到主线程来解决它,并继续减少时间以查看它是否有意义。我最终得到了这个:

DispatchQueue.main.async(execute: {
   self.tableView.setEditing(false, animated: true)
})
Run Code Online (Sandbox Code Playgroud)

解决了这个问题,尽管之后你有一些奇怪的删除动画,可能是由于 tableView 的切换状态和 iOS 11 SDK 中的一些内部竞争条件所致。