I have a view in my app with many labels and a toolbar with some buttons. I would like to edit all the labels at the same time when pressing a button. I thought it might be a way to "popup" a text input and make a keyboard appear at the same time. Which is the cleanest way to do that? Thank you
http://discussions.apple.com/thread.jspa?messageID=8445879
Alternatively. Here's how I do it:
UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Please enter your name:"
message:@"\n\n"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Enter", nil];
textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 260, 25)];
[textField setBackgroundColor:[UIColor whiteColor]];
[textField setPlaceholder:@"Name for message"];
[prompt addSubview:textField];
[textField release];
// show the dialog box
[prompt show];
[prompt release];
// set cursor and show keyboard
[textField becomeFirstResponder];
Then in the UIAlertView delegate method you read the content from textField.text :-)
I know its too late answer,But this answer for those who are using iOS 5.0 or later. Now AlertView has new Property AlertViewStyle for various purpose.
UIAlertViewStyle
The presentation style of the alert.
typedef enum {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
} UIAlertViewStyle;
Example:
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
[alertView release];
Delegate:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%@",[[alertView textFieldAtIndex:0] text])
}
Reference : http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With