Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding TextField to UIAlertView

I need to add a TextField to an UIAlertView. I understand that apple discourage this approach. So is there any library that i could make use of to add a TextField to a UIAlertView look-alike frame ?

like image 201
shajem Avatar asked Apr 01 '12 06:04

shajem


2 Answers

For iOS5:

UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Title" message:@"Please enter someth" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
[av textFieldAtIndex:0].delegate = self;
[av show];

Also, you 'll need to implement UITextFieldDelegate, UIAlertViewDelegate protocols.

like image 152
Shmidt Avatar answered Nov 15 '22 00:11

Shmidt


Unfortunately the only official API for this is iOS 5 and up, it's a property called alertViewStyle which can be set to the following parameters:

UIAlertViewStyleDefault
UIAlertViewStyleSecureTextInput
UIAlertViewStylePlainTextInput
UIAlertViewStyleLoginAndPasswordInput

UIAlertViewStylePlainTextInput being the one you want.

Messing with the view hierarchy as described above is strongly discouraged by Apple.

like image 14
Brandon Tennant Avatar answered Nov 14 '22 22:11

Brandon Tennant