
I found this problem in working project. After I've created the simplest UIAlertController with textfield in empty project and found same problem. Looks like system bug?
How to reproduce: Launch code below in portrait mode and then rotate to landcape.
I checked in simulators 15 Pro, 14 Pro, iOS 17/16. Everything is fine on iPhone SE.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let alertController = UIAlertController(title: "Alert Title", message: "This is a sample alert.", preferredStyle: .alert)
alertController.addTextField { (textField) in
textField.placeholder = "Additional Text"
}
let okAction = UIAlertAction(title: "OK", style: .default) { (action) in
if let textField = alertController.textFields?.first {
print("Additional Text: \(textField.text ?? "")")
}
}
alertController.addAction(okAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
}
No, it's not a system bug. It seems like you might be encountering issues related to a third-party library. I recommend using the native iOS built-in feature UIAlertController for displaying alerts, as shown in the provided code example:
If the issue persists, it would be helpful to see more code or receive additional information about the problem you are facing.