iOS 11 UITableView isEditing 标志设置不正确

标签 ios swift uitableview swift3 ios11

我在使用 iOS 11 SDK 时遇到了一个非常奇怪的问题。 使用滑动手势删除单元格后,在 iOS 11 设备和模拟器上将 UITableView 的 editing 标志设置为 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)
}

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

最佳答案

我遇到了类似的问题,并尝试通过延迟分派(dispatch)到主线程来解决它,并不断减少时间以查看它是否有意义。我最终得到了这个:

DispatchQueue.main.async(execute: {
   self.tableView.setEditing(false, animated: true)
})

解决了这个问题,虽然你之后有一点奇怪的删除动画,大概是由于 tableView 的切换状态和 iOS 11 SDK 中的一些内部竞争条件。

关于iOS 11 UITableView isEditing 标志设置不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345248/

相关文章:

swift - 来自带有 @objc 的未识别选择器的实例错误

iphone - 为什么 UITableViewController self.tableView 属性在 UIPopoverController 中呈现时为 Nil?

ios - [__NSConcreteURLComponents 查询项] : unrecognized selector

ios - iOS 设备上的语言更改

php - AFNetworking 将 UIImage 上传为 NSData -> PHP 脚本移动文件

ios - iOS 5 更新后,我的文档目录中的文件不见了? iOS 是否正在更改文档目录?

swift - 无法获取 firebase 子节点

ios - 导航到特定的 TabBar 项

iphone - TableView 中的“EXC_BAD_ACCESS”, "[TasksPageViewController tableView:numberOfRowsInSection:]"

iphone - 在tableView中选择多个单元格并将所选单元格显示在另一个tableView单元格中作为标签?