Questions tagged [uialertcontroller]

An iOS class, for displaying alerts and popup style selectors. Note that the legacy `UIActionSheet` and `UIAlertView` tags would not generally be used now.

In iOS, UIAlertController displays an alert message to the user, or, an action selector. (On iPhone, it's the large selector which appears from the bottom of the screen, usually with two or three choices.)

After configuration, it is presented using UIViewController.present. In the action sheet case, actions are added using UIAlertController.addAction.

This class replaced the older UIActionSheet and UIAlertView.

Apple UIAlertController Documentation

1683 questions
552
votes
36 answers

How would I create a UIAlertView in Swift?

I have been working to create a UIAlertView in Swift, but for some reason I can't get the statement right because I'm getting this error: Could not find an overload for 'init' that accepts the supplied arguments Here is how I have it…
BlueBear
  • 7,469
  • 6
  • 32
  • 47
292
votes
39 answers

How to present UIAlertController when not in a view controller?

Scenario: The user taps on a button on a view controller. The view controller is the topmost (obviously) in the navigation stack. The tap invokes a utility class method called on another class. A bad thing happens there and I want to display an…
Murray Sagal
  • 8,454
  • 4
  • 47
  • 48
218
votes
15 answers

Presenting a UIAlertController properly on an iPad using iOS 8

With iOS 8.0, Apple introduced UIAlertController to replace UIActionSheet. Unfortunately, Apple didn't add any information on how to present it. I found an entry about it on hayaGeek's blog, however, it doesn't seem to work on iPad. The view is…
Matt3o12
  • 4,192
  • 6
  • 32
  • 47
161
votes
5 answers

How to get input value from a UIAlertController text field?

I'm trying to make an alert controller with message and input, and then get the value from the input. I've found many good tutorials on how to make the input text field, but I can't get the value from the alert.
ntoonio
  • 3,024
  • 4
  • 24
  • 28
136
votes
1 answer

UIAlertController's actionSheet gives constraint error on iOS 12.2 / 12.3

On iOS 12.2, while using UIAlertController's actionSheet, Xcode gives constraint error. Anyone having this problem? This same code runs on iOS 12.1 with no error. I have tested this code on Xcode 10.2 and 10.1. class ViewController: UIViewController…
L03n
  • 1,421
  • 2
  • 10
  • 12
127
votes
24 answers

UIAlertController custom font, size, color

I am using new UIAlertController for showing alerts. I have this code: // nil titles break alert interface on iOS 8.0, so we'll be using empty strings UIAlertController *alert = [UIAlertController alertControllerWithTitle: title == nil ? @"": title…
Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
119
votes
10 answers

UIAlertView first deprecated IOS 9

I have tried several ways to use UIAlertController,instead of UIAlertView. I tried several ways but I cannot make the alert action work. Here is my code that works fine in IOS 8 and IOS 9 but is showing up with deprecated flags. I tried the…
Bux
  • 1,273
  • 2
  • 9
  • 9
118
votes
13 answers

What is the best way to check if a UIAlertController is already presenting?

I have a tableview which, when loaded, each cell could possibly return an NSError, which I have chosen to display in a UIAlertController. Problem is I get this error in the console if multiple errors are returned. Warning: Attempt to present…
hidden-username
  • 2,610
  • 3
  • 14
  • 19
114
votes
10 answers

Writing handler for UIAlertAction

I'm presenting a UIAlertView to the user and I can't figure out how to write the handler. This is my attempt: let alert = UIAlertController(title: "Title", message: "Message", preferredStyle:…
Steve Marshall
  • 7,919
  • 4
  • 16
  • 17
108
votes
14 answers

How to add TextField to UIAlertController in Swift

I am trying to show a UIAlertController with a UITextView. When I add the line: //Add text field alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in } I get a Runtime error: fatal error: unexpectedly…
Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
64
votes
11 answers

How to dismiss UIAlertController when tap outside the UIAlertController?

How to dismiss UIAlertController when tap outside the UIAlertController? I can add a UIAlertAction of style UIAlertActionStyleCancel to dismiss the UIAlertController. But I want to add the function that when user tap outside the UIAlertController…
leizh00701
  • 1,893
  • 5
  • 21
  • 32
64
votes
8 answers

Add Image to UIAlertAction in UIAlertController

I have seen a couple screen shots of a UIAlertControllers with an image on the left of the row but I do not seen it in the documentation. An example visual is Here is the code that I have for my controller right now: UIAlertController * view…
user1079052
  • 3,803
  • 4
  • 30
  • 55
63
votes
5 answers

iOS UIAlertController bold button changed in 8.3

UIAlertController with two buttons with styles set: UIAlertActionStyle.Cancel UIAlertActionStyle.Default in iOS 8.2, the Cancel button is non-bold and Default is bold. In iOS 8.3 they have switched round You can see it Apple's own apps e.g.,…
Bbx
  • 3,184
  • 3
  • 22
  • 33
61
votes
6 answers

How to hide title/message frame in a UIAlertController?

When using a UIAlertController, if I want to present a UIActionSheet with an empty title and an empty message, the frame for the expected placement of the title and/or message remains. How do I change this so that I only present an ActionSheet that…
vlin
  • 825
  • 1
  • 6
  • 13
60
votes
4 answers

How to add textField in UIAlertController?

I want to realize a function about changing password. It requires users to input their previous password in an alert dialog. I want to click the button "Confirm the modification" then jump to the other view controller for changing password. I have…
Juice007
  • 1,054
  • 1
  • 9
  • 14
1
2 3
99 100