Alex Rivera | Logout

How can I init a text field in a UIAlertView

Asked 2012-03-08T14:36:39.327
29

The updated UIAlertView now has a style which allows a Text input field in UIAlertView i.e.

alert.alertViewStyle = UIAlertViewStylePlainTextInput;

This works well but I wanted to init the input text with a defualt text like "sample".

I see that folks in the past have used undocumented api like (which works great)

[alert addTextFieldWithValue:@"sample text" label:@"Text Field"];

but since this is still not an official Apple public API I can't use it.

Any other way to handle this? I did try to init in willPresentAlertView but text field seem to be read-only.

Thanks

Edit
Report

1 Answer

6

For setting default value in uiAlertView this thing will work.

UIAlertView *alert = ....
UITextField *textField = [alert textFieldAtIndex:0];
[textField setText:@"My default text"];
[alert show];
answered 2012-12-31T11:31:05.597

Your Answer