AlertController is not in the window hierarchy

If you’re instancing your UIAlertController from a modal controller, you need to do it in viewDidAppear, not in viewDidLoad or you’ll get an error. Here’s my code (Swift 4): override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let alertController = UIAlertController(title: “Foo”, message: “Bar”, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: “OK”, style: .cancel, handler: nil)) present(alertController, animated: true, completion: … Read more

How to add text input in alertview of ios 8?

Screenshot Code UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @”Login” message: @”Input username and password” preferredStyle:UIAlertControllerStyleAlert]; [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @”name”; textField.textColor = [UIColor blueColor]; textField.clearButtonMode = UITextFieldViewModeWhileEditing; textField.borderStyle = UITextBorderStyleRoundedRect; }]; [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @”password”; textField.textColor = [UIColor blueColor]; textField.clearButtonMode = UITextFieldViewModeWhileEditing; textField.borderStyle = UITextBorderStyleRoundedRect; textField.secureTextEntry = YES; }]; [alertController … Read more

How to use UIAlertController to replace UIActionSheet?

I have used following code to show action sheet using UIAlertViewController and it works perfect. Swift let alert = UIAlertController(title: “Action Title”, message: “Action Message”, preferredStyle: .actionSheet) let action = UIAlertAction(title: “Item”, style: .default) { UIAlertAction in // Write your code here } alert.addAction(action) let cancelAction = UIAlertAction(title: “Cancel”, style: .cancel) { UIAlertAction in // … Read more

UIAlertController – add custom views to actionsheet

UIAlertController extends UIViewController, which has a view property. You can add subviews to that view to your heart’s desire. The only trouble is sizing the alert controller properly. You could do something like this, but this could easily break the next time Apple adjusts the design of UIAlertController. Swift 3 let alertController = UIAlertController(title: “\n\n\n\n\n\n”, … Read more

UIAlertView/UIAlertController iOS 7 and iOS 8 compatibility

The detection pattern is identical to the Objective-C style. You need to detect whether the current active runtime has the ability to instantiate this class if objc_getClass(“UIAlertController”) != nil { println(“UIAlertController can be instantiated”) //make and use a UIAlertController } else { println(“UIAlertController can NOT be instantiated”) //make and use a UIAlertView } Don’t try … Read more

Presenting a view controller modally from an action sheet’s delegate in iOS8 – iOS11

Update: As of iOS 9 SDK, UIActionSheet is deprecated, so do not expect a fix regarding this issue. It is best to start using UIAlertController when possible. The problem seems to come from Apple’s switch to using UIAlertController internally to implement the functionality of alert views and action sheets. The issue is seen mostly on … Read more

How to add textField in UIAlertController?

You will get all added textfields from alert controller by its textFields readonly property, you can use it to get its text. Like Swift 4: let alertController = UIAlertController(title: “”, message: “”, preferredStyle: .alert) alertController.addTextField { textField in textField.placeholder = “Password” textField.isSecureTextEntry = true } let confirmAction = UIAlertAction(title: “OK”, style: .default) { [weak alertController] … Read more

tech