Luke
Luke

Reputation: 9710

How to retrieve text from UIAlertViewStylePlainTextInput

I'm calling a UIAlertView with the PlainTextView style, and I'm trying to work out how I can get access to whatever the user entered in the text view before they clicked OK.

I'm using willDismissWithButtonIndex and the alertView doesn't seem to have any properties like text, or anything.

How can I get at it? Thanks in advance!

Upvotes: 9

Views: 8960

Answers (3)

Mario
Mario

Reputation: 4520

Get the text field with

UITextField *textfield =  [alertView textFieldAtIndex: 0];

In your delegate method. Refer to the documentation for further information.

Edit march 2015 due to many views the swift equivalent :

let textfield = alertView.textFieldAtIndex(0)

Upvotes: 37

user3388273
user3388273

Reputation: 399

UITextField *textfield = [alertView textFieldAtIndex: 0];

Use this in uialertview delegate

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
   UITextField *textfield =  [alert_name textFieldAtIndex: 0];
 }

Upvotes: 3

Adam Lockhart
Adam Lockhart

Reputation: 1195

Use its method:

- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex

For index 0.

Upvotes: 0

Related Questions