if you want to remove an article from website contact us from top.

    identify the terms that characterise cheetah a. defensive, meek b. alert, swift c. fierce, sluggish d. wild, submissive

    Mohammed

    Guys, does anyone know the answer?

    get identify the terms that characterise cheetah a. defensive, meek b. alert, swift c. fierce, sluggish d. wild, submissive from screen.

    UIAlertController

    An object that displays an alert message.

    Class

    UIAlertController

    An object that displays an alert message.

    iOS 8.0+ iPadOS 8.0+ Mac Catalyst 13.1+ tvOS 9.0+

    Declaration

    @MainActor class UIAlertController : UIViewController

    Overview

    Use this class to configure alerts and action sheets with the message that you want to display and the actions from which to choose. After configuring the alert controller with the actions and style you want, present it using the present(_:animated:completion:) method. UIKit displays alerts and action sheets modally over your app’s content.

    In addition to displaying a message to a user, you can associate actions with your alert controller to give people a way to respond. For each action you add using the addAction(_:) method, the alert controller configures a button with the action details. When a person taps that action, the alert controller executes the block you provided when creating the action object. The following code shows how to configure an alert with a single action.

    let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)

    alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in

    NSLog("The \"OK\" alert occured.")

    }))

    self.present(alert, animated: true, completion: nil)

    When configuring an alert with the UIAlertController.Style.alert style, you can also add text fields to the alert interface. The alert controller lets you provide a block for configuring your text fields prior to display. The alert controller maintains a reference to each text field so that you can access its value later.

    Important

    The UIAlertController class is intended to be used as-is and doesn’t support subclassing. The view hierarchy for this class is private and must not be modified.

    Topics

    Creating an alert controller

    init(title: String?, message: String?, preferredStyle: UIAlertController.Style)

    Creates and returns a view controller for displaying an alert.

    Configuring the alert

    var title: String?

    The title of the alert.

    var message: String?

    Descriptive text that provides more details about the reason for the alert.

    var preferredStyle: UIAlertController.Style

    The style of the alert controller.

    Configuring the user actions

    func addAction(UIAlertAction)

    Attaches an action object to the alert or action sheet.

    var actions: [UIAlertAction]

    The actions that the user can take in response to the alert or action sheet.

    var preferredAction: UIAlertAction?

    The preferred action for the user to take from an alert.

    Configuring text fields

    func addTextField(configurationHandler: ((UITextField) -> Void)?)

    Adds a text field to an alert.

    var textFields: [UITextField]?

    The array of text fields displayed by the alert.

    Configuring alert severity

    var severity: UIAlertControllerSeverity

    Indicates the severity of the alert.

    enum UIAlertControllerSeverity

    Constants for specifying the severity of an alert in apps built with Mac Catalyst.

    Constants

    enum UIAlertController.Style

    Constants indicating the type of alert to display.

    Relationships

    Inherits From

    UIViewController

    Conforms To

    UISpringLoadedInteractionSupporting

    See Also

    Alerts

    Getting the user’s attention with alerts and action sheets

    Present important information to the user or prompt the user about an important choice.

    class UIAlertAction

    An action that can be taken when the user taps a button in an alert.

    स्रोत : developer.apple.com

    ios

    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

    How would I create a UIAlertView in Swift?

    Ask Question

    Asked 8 years, 3 months ago

    Modified 9 months ago

    Viewed 689k times 541

    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 written:

    let button2Alert: UIAlertView = UIAlertView(title: "Title", message: "message",

    delegate: self, cancelButtonTitle: "OK", otherButtonTitles: nil)

    Then to call it I'm using:

    button2Alert.show()

    As of right now it is crashing and I just can't seem to get the syntax right.

    iosswiftcocoa-touchuialertviewuialertcontroller

    Share

    Improve this question

    edited Mar 26, 2018 at 2:50

    Dmitry 13.9k21 21 gold badges 103 103 silver badges 186 186 bronze badges

    asked Jun 3, 2014 at 18:35

    BlueBear 7,3596 6 gold badges 31 31 silver badges 47 47 bronze badges 6

    UIAlertView and UIActionSheet has been replaced by UIAlertController in iOS 8, have you looked at this? –

    Popeye

    Jun 3, 2014 at 18:51

    Make sure the class that self belongs to adopts the protocol UIAlertViewDelegate (the recommended way to do this, in Swift, is with an extension). –

    Nicolas Miari

    Jul 14, 2015 at 7:37

    @Adam: I have reverted your retagging. The swift3 tag is for And I don't think that from meta.stackoverflow.com/questions/252079/… applies here. –

    Martin R

    Jul 13, 2017 at 14:13

    1

    @MartinR I don't know how questions can be updated to show that there are answers that apply to a current version of Swift; there is a lot of old, useless stuff here and [swift] finds it all along with the useful. I don't feel strongly about this retag being reverted but I wish there was a definitive way to solve this problem. (I wish answers had tags.) –

    Adam Eberbach

    Jul 14, 2017 at 0:50

    Add a comment

    36 Answers

    1 2 Next 980

    From the UIAlertView class:

    // UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

    On iOS 8, you can do this:

    let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)

    alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))

    self.presentViewController(alert, animated: true, completion: nil)

    Now UIAlertController is a single class for creating and interacting with what we knew as UIAlertViews and UIActionSheets on iOS 8.

    Edit: To handle actions:

    alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { action in

    switch action.style{

    case .Default: print("default") case .Cancel: print("cancel") case .Destructive:

    print("destructive")

    } }}))

    Edit for Swift 3:

    let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.alert)

    alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))

    self.present(alert, animated: true, completion: nil)

    Edit for Swift 4.x:

    let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: .alert)

    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in

    switch action.style{

    case .default: print("default") case .cancel: print("cancel") case .destructive:

    print("destructive")

    } }))

    self.present(alert, animated: true, completion: nil)

    Share Improve this answer

    edited Mar 29, 2021 at 2:51

    aheze 18.2k5 5 gold badges 44 44 silver badges 95 95 bronze badges

    answered Jun 3, 2014 at 18:48

    Oscar Swanros 19.5k5 5 gold badges 31 31 silver badges 48 48 bronze badges 3

    Where did you see that UIAlertView is deprecated? I don't see that in the documentation? –

    BlueBear

    Jun 3, 2014 at 18:58

    9

    Cmd + Click the UIAlertView class, and the comment is right on top of the class declaration. –

    Oscar Swanros

    Jun 3, 2014 at 19:00

    2

    I'll answer my own question for anyone else who's curious alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (ACTION :UIAlertAction!)in })) –

    altyus

    Jun 3, 2014 at 20:27

    5

    What's the point of Cancel and Destructive cases since it will always be what you specified .Default? –

    User

    Sep 21, 2014 at 3:42

    4

    Reading this answer the switch case you did is unnecessary. The switch is only useful if the type, or title aren't hardcoded ie they are dynamic: –

    mfaani

    Nov 30, 2016 at 17:27

    Show 4 more comments

    537 +50

    One Button

    class ViewController: UIViewController {

    @IBAction func showAlertButtonTapped(_ sender: UIButton) {

    // create the alert

    let alert = UIAlertController(title: "My Title", message: "This is my message.", preferredStyle: UIAlertController.Style.alert)

    स्रोत : stackoverflow.com

    UIAlertController in Swift. UIAlertController is one of the most…

    UIAlertController is one of the most basic component of the app development, because using the UIAlertController to get the feedback, confirmation, choose between the options from the user, also we…

    UIAlertController in Swift

    UIAlertController is one of the most basic component of the app development, because using the UIAlertController to get the feedback, confirmation, choose between the options from the user, also we do alerts.

    Components

    Title : The title of the alert.Alert Message : Descriptive text that provides more details about the reason for the alert.Alert Style : Indicating the type of alert to display.Alert Actions : The actions that the user can take in response to the alert or action sheet.Alert TextField : Text field displayed by the alert.

    Alert Styles: Alert Or Action Sheet?

    When creating your alert controller, you can choose between two options from enum UIAlertControllerStyle

    .alert : An alert displayed modally for the app..actionSheet : An action sheet displayed in the context of the view controller that presented it.

    Ready? Let’s go, 👨‍💻

    Simple alert

    Simple action sheet

    Alert with distractive button

    Alert with more than 2 buttons

    Alert with UITextField

    If you want to validate the input box, add delegate to the UITextField and you can validate as normally we do for others.

    iBlahji/Example-UIAlertController

    Example-UIAlertController - UIAlertController in swift

    github.com

    स्रोत : medium.com

    Do you want to see answer or more ?
    Mohammed 6 day ago
    4

    Guys, does anyone know the answer?

    Click For Answer