我有一个UITableView,其单元格具有可替换的UIContextualActions来删除或重命名(编辑)单个单元格的TextFields。
由于我切换到Swift 5 / iOS 13,在这些单元格上触发重命名UIContextualAction会导致键盘启动,并在用户有机会输入之前立即关闭。不仅键盘消失了,我试图编辑的特定单元格也变得完全空了,并生成了以下警告:
[Snapshotting] Snapshotting a view (0x10c90a470, _UIReplicantView) that has not been rendered at least once requires afterScreenUpdates:YES.下面是重命名UIContextualAction的代码
let actionRename = UIContextualAction(style: .normal, title: "") { (action, view, completionHandler) in
let cell = self.tableLayers.cellForRow(at: indexPath) as! LayerUITableViewCell
cell.layerTitle.isEnabled = true // enable UITextField editing
cell.layerTitle.becomeFirstResponder() // launch keyboard
cell.layerTitle.selectedTextRange = cell.layerTitle.textRange(from: (cell.layerTitle.beginningOfDocument), to: (cell.layerTitle.endOfDocument)) // select all text
completionHandler(true)
} // end of let actionRename我猜UIContextual动作的动画以某种方式触发了键盘的resignFirstResponder。
总之,在swift 5/iOS 13之前,事件的顺序如下所示:
用户滑动单元left/right
resignFirstResponder而我在迁移之后看到的行为是这样的:
用户滑动单元格left/right
resignFirstResponder)
resignFirstResponder更新2019/10/02
我已经确认是细胞动画导致了过早的键盘拒绝。如果我在completionHandler之后引入延迟,如下所示:
let actionRename = UIContextualAction(style: .normal, title: "") { (action, view, completionHandler) in
completionHandler(true)
self.perform(#selector(self.layerRenameDos), with: nil, afterDelay: 1.0)
// layerRenameDos has the editing/firstResponder code from above
} // end of let actionRename有了这个改变,这个单元格就会回复到中央,键盘就会启动,我就可以打字了。然而,这显然是一个棘手的问题。如有任何建议,将不胜感激
发布于 2019-11-22 09:52:14
我认为这是一个更好的解决办法。只需确保在下一个运行循环中执行您的代码。
CATransaction.begin()
CATransaction.setCompletionBlock {
DispatchQueue.main.async {
//your code on the next runloop after the animation has finished
}
}
complitionHandler(true)
// or tableView.setEditing(false, animated: true)
CATransaction.commit()https://stackoverflow.com/questions/58179858
复制相似问题