I have an iPad app. I am creating an UIAlertController and adding a textfield. It crashes. It only crashes when I add a textfield.
let alert = UIAlertContr
This seems to have something to do with styling the UIAlertController's view, as eluded to by @BigShay.
In my example I set the tintColor of the view before adding the UITextField and I crash in iOS 8. The workaround given by @Baza207 to add the UITextField after displaying the alert avoids the crash in iOS 8, however it also results in no text field appearing at all in iOS 9.
If you just move the styling to after adding the text field, it works with both iOS 8 and iOS 9 (no crash in iOS 8, and no missing text field in iOS 9):
Crash in iOS 8
Works in iOS 9
alertController.view.tintColor = UIColor.blueColor()
alertController.addTextFieldWithConfigurationHandler { textField in
}
presentViewController(alertController, animated: true, completion: nil)
Works in iOS 8
No text text field in iOS 9
alertController.view.tintColor = UIColor.blueColor()
presentViewController(alertController, animated: true, completion: nil)
alertController.addTextFieldWithConfigurationHandler { textField in
}
Works in iOS 8
Works in iOS 9
alertController.addTextFieldWithConfigurationHandler { textField in
}
alertController.view.tintColor = UIColor.blueColor()
presentViewController(alertController, animated: true, completion: nil)