Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get input from UIAlertView?

I want take player name as input by using UIAlertView. Is it possible to add textField on the UIAlertView?

like image 318
SST Avatar asked May 19 '09 13:05

SST


People also ask

How to transition from UIAlertView to uialertcontroller in iOS 8?

As of iOS 8, it is recommended to use the UIAlertController class to present action sheets and modal alerts. In this quick tip, I will show you how easy it is to transition from UIAlertView to UIAlertController. 1. Project Setup Launch Xcode 6.3+ and create a new project based on the Single View Application template.

How do I subclass the UIAlertView class?

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. A preview action, or peek quick action, that is displayed below a peek when a user swipes the peek upward.

What is an alert view in iOS?

In apps that run in versions of iOS prior to iOS 8, use the UIAlertView class to display an alert message to the user. An alert view functions similar to but differs in appearance from an action sheet (an instance of UIActionSheet ).

What is the preferred style for uialertcontrollerstyle?

We pass in a title, a message, and, most importantly, set the preferred style to UIAlertControllerStyle.Alert or .Alert for short. The preferred style tells the operating system if the alert controller needs to be presented as an action sheet, .ActionSheet, or a modal alert, .Alert.


2 Answers

Since iOS 5, UIAlertView provides this: change the alertViewStyle property to one of the following:

UIAlertViewStylePlainTextInput (1 text field)
UIAlertViewStyleSecureTextInput (1 password field)
UIAlertViewStyleLoginAndPasswordInput (both a text field and password field)

Then use textFieldAtIndex: to get the text field you want. This way, you can even use the alertViewShouldEnableFirstOtherButton: delegate method to enable the button.

like image 173
Tustin2121 Avatar answered Sep 20 '22 20:09

Tustin2121


Yes, it's definitely possible, and it isn't a hack. You would need to subclass UIAlertView and place controls into it. Since it's a subclass, it will retain the same look & feel, etc.

For full details, see this tutorial by Jeff LaMarche (co-author of Beginning iPhone Development, from Apress).

like image 31
Jim Dovey Avatar answered Sep 17 '22 20:09

Jim Dovey