Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 270
Luke Avatar asked Dec 15 '12 17:12

Luke


2 Answers

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)
like image 174
Mario Avatar answered Sep 18 '22 16:09

Mario


UITextField *textfield = [alertView textFieldAtIndex: 0];

Use this in uialertview delegate

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
   UITextField *textfield =  [alert_name textFieldAtIndex: 0];
 }
like image 41
user3388273 Avatar answered Sep 18 '22 16:09

user3388273