I have a simple view with a text field that becomes the first responder when the view loads. If the user enters the wrong code, an 'oops' alert dialogue pops up, and the keyboard dismisses, and upon clicking an option on the alert dialogue, the keyboard appears again, resulting in my view moving about.
Is there a way to stop this keyboard - ever - dismissing? I tried to use this I found elsewhere:
override var disablesAutomaticKeyboardDismissal: Bool { return true }
however it doesn't seem to fix the problem. Could anyone give me a heads up? :) Thanks!
fixed with the following solution, modified from this answer - https://stackoverflow.com/a/47068284/14815664
func displayError(message: String) {
let controller = UIAlertController(title: "Oops!", message: message, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "Dismiss", style: .default))
guard let alertWindow = UIApplication.shared.windows.last,
alertWindow.windowLevel == UIWindow.Level(rawValue: 10000001.0) else {
navigationController.present(controller, animated: true, completion: nil)
return
}
alertWindow.rootViewController?.present(controller, animated: true, completion: nil)
}