Fix crash due to PencilKit undo manager not being available until viewDidAppear

This commit is contained in:
Shadowfacts 2021-06-10 10:33:24 -04:00
parent 2a05b6d326
commit 7c9287543c
1 changed files with 6 additions and 5 deletions

View File

@ -80,12 +80,13 @@ class ComposeDrawingViewController: UIViewController {
updateLayout(for: toolPicker) updateLayout(for: toolPicker)
canvasView.becomeFirstResponder() canvasView.becomeFirstResponder()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// wait until the next run loop iteration so that the canvas view has become first responder and it's undo manager exists NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidUndoChange, object: self.undoManager!)
DispatchQueue.main.async { NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!)
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidUndoChange, object: self.undoManager!)
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!)
}
} }
func updateLayout(for toolPicker: PKToolPicker) { func updateLayout(for toolPicker: PKToolPicker) {