iOS 11 UITableView isEditing标志设置不正确

iOS 11 UITableView isEditing标志设置不正确,ios,swift,uitableview,swift3,ios11,Ios,Swift,Uitableview,Swift3,Ios11,我在使用iOS 11 SDK时遇到了一个非常奇怪的问题。 在使用滑动手势删除单元格后,将iOS 11设备和模拟器上的UITableView的编辑标志设置为false时,设置后的下一行仍保持true。 在iOS 10设备及以下设备上,该标志被正确设置为false。 请看一下这个简短的例子 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true }

我在使用iOS 11 SDK时遇到了一个非常奇怪的问题。 在使用滑动手势删除单元格后,将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)
}
func tableView(tableView:UITableView,canEditRowAt indexath:indexPath)->Bool{
返回真值
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
让cell:UITableViewCell=tableView.dequeueReusableCell(标识符:cellReuseIdentifier)作为UITableViewCell!
返回单元
}
func tableView(tableView:UITableView,commit editingStyle:UITableViewCellEditingStyle,forRowAt indexPath:indexPath){
如果editingStyle==.delete{
tableView.deleteRows(位于:[indexPath],带:.fade)
endEditingMode()
}
}
func endEditingMode(){
tableView.setEditing(假,动画:真)
//在这里,我们期望'isEditing=false',因为它在前面设置了一行,但在iOS 11设备上仍然是'true'

//在上,我遇到了类似的问题,并试图通过延迟发送到主线程来解决它,并不断缩短时间,看看它是否有意义。我最终遇到了以下问题:

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

解决了这个问题,尽管之后会出现一些奇怪的删除动画,这可能是由于tableView的切换状态和iOS 11 SDK中的某些内部争用条件造成的。

尝试使用UISwipeActionsConfiguration(iOS 11 API)使用UIContextualAction。执行操作后,应从UIContextualActionHandler调用块。此块将触发关闭滑动动画。然后使用带完成块的CATTransaction将UITableView编辑设置为否

[CATransaction begin];
[CATransaction setCompletionBlock:^{
   [self.tableView setEditing:NO animated:NO];
}];
completionHandler(YES); // From UIContextualAction
[CATransaction commit];

这是添加到UIViewController的UITableViewController还是表视图?表最初是如何设置为编辑模式的?它是添加到UIViewController的tableView,再说一遍,表最初是如何设置为编辑模式的?啊,很抱歉,错过了那个。当我们使用滑动删除函数时,编辑被设置为true.Hm。如果您在
setEditing
之后将块分配到主队列,并选中
tableView。是否在块内编辑
?我的假设是,表视图结束编辑,只是不同步。