Working with UIAlertView class in iOS

Опубликовано: 12 Март 2026
на канале: techytube
389
1

Subscribe to our channel here for notifications on new video trainings. For more videos on technology, visit our website at http://www.techytube.com.
By pavel@techytube, for more from this author visit:
http://www.techytube.com/author/pavel

When we want our app to display an alert message to the user we use the UIAlertView class.
Use the properties and methods defined in this class to set the title, message, and delegate of an alert view and configure the buttons. You must set a delegate if you add custom buttons. The delegate should conform to the UIAlertViewDelegate protocol. Use the show method to display an alert view once it is configured.

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

You have to show alert to the users only when it is absolutely necessary, which is also recommended by Apple's engineers.

In iOS 5 and up we have some additional customisation possibilities that we can apply to the UIAlertView objects. We achieve that by using its alertViewStyle property.

We have 4 options:

// the default one
alert.alertViewStyle = UIAlertViewStyleDefault;

// an alert with text input inside it
alert.alertViewStyle = UIAlertViewStylePlainTextInput;

// an alert with password-like text input inside it
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;

// an alert with 2 text input fields - one for Login and one for Password
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;


For more you can check Apple's Online Documentation at:
http://developer.apple.com/library/io...