Is it possible to show an alertview with a textbox inside like the AppStore app. It asks for password in such a dialog. I've seen atleast a couple of other third party apps using it. Is it a private API?
+7
A:
Yes, it's undocumented. To add a text field to UIAlertView, use addTextFieldWithValue: label: method. You call with the default text as the first argument and the text that displays in an empty field as the second. Having done that, you can access the field via using textFieldAtIndex:n - see below.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Who are you?"
message:@"Give your full name"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert addTextFieldWithValue:@""label:@"Name"];
// Customise name field
UITextField* name = [alert textFieldAtIndex:0];
name.clearButtonMode = UITextFieldViewModeWhileEditing;
name.keyboardType = UIKeyboardTypeAlphabet;
name.keyboardAppearance = UIKeyboardAppearanceAlert;
[alert show];
The next snippet shows how to retrieve the value in the name field:
NSLog("Name is %@", [[modalView textFieldAtIndex:0] text]);
Jane Sales
2009-05-07 09:04:33
As other people already mentioned, this will get you kicked from the app store nowadays.
zoul
2010-09-09 08:19:18
Agreed - this was written a long time ago. Should I delete the answer.
Jane Sales
2010-09-15 14:18:09
+3
A:
Jeff Lamarche posted some sample code on his blog to do just this. The formatting looked a bit wonky when I tried it but it's probably a good starting point.
Stephen Darlington
2009-05-07 09:07:56
A:
I confirm what eisernWolf said, Apple reject my app for using this method. better add the textbox as a sub view
Tamer
2010-06-30 19:41:22
A:
Private APIs are in the top 3, as Steve Jobs said during 2010 keynote speech.
Bovine
2010-07-17 22:40:19