I have a alert view that has a text field inside of it. Here is the code:
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Password" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Enter", nil];
[myAlert addTextFieldWithValue:nil label:@"Type Password"];
[[myAlert textField] setSecureTextEntry:YES];
[[myAlert textField] setDelegate:self];
[[myAlert textField] setTextAlignment:UITextAlignmentCenter];
[[myAlert textField] becomeFirstResponder];
[myAlert show];
[myAlert release];
myAlert = nil;
I get 4 warnings, each on the lines that include [[myAlert textField]. The warnings I get are “Method -addTextFieldWithValue:label: not found (return type defaults to ‘id’)” and “Method '-textField' not found (return type defaults to ‘id’).” What should I do to fix these? Is there a better way to display a text field within an alert view without any warnings?
The reason for your warnings is that the
UIAlertViewclass doesn’t have any such methods asaddTextFieldWithValueortextField.Generally speaking, alert views are not intended for input, other than allowing a choice between a few basic options (“yes/no”, “ok/cancel”, etc). If you need a user to type in a password, your text field should be somewhere on a regular view. It is for exactly this reason the kind of methods you are after are not implemented in
UIAlertView.For reference:
UIAlertView