Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 XCode 5 - UIAlertView with TextField - How to pull text into a Label or NSString? [duplicate]

UIAlertView *alertViewChangeName=[[UIAlertView alloc]initWithTitle:@"Change Name" message:@"What is your teacher's name?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
alertViewChangeName.alertViewStyle=UIAlertViewStylePlainTextInput;
[alertViewChangeName show];

I am just looking to retrieve the input from the textbox and place it within a UILabel or an NSString to later use and/or manipulate.

like image 293
hevansa98 Avatar asked Aug 22 '14 04:08

hevansa98


2 Answers

You will need to invoke UIAlertView's delegate method

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
     NSString *test = [[alertView textFieldAtIndex:0] text];
}
like image 62
Yogesh Suthar Avatar answered Oct 03 '22 20:10

Yogesh Suthar


You just need to use the -textFieldAtIndex: method on UIAlertView to get your Textfield. e.g:

UIAlertView *alert = ...
UITextField *textInput = [alert textFieldAtIndex:0];
textInput.text = ...

// get user input
NSString *userInput = textInput.text;
like image 29
Oxcug Avatar answered Oct 03 '22 22:10

Oxcug