Nev*_*vin 10
http://discussions.apple.com/thread.jspa?messageID=8445879
另外.我是这样做的:
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];
Run Code Online (Sandbox Code Playgroud)
然后在UIAlertView委托方法中,您从textField.text中读取内容:-)
iNe*_*eal 10
我知道它的答案太迟了,但对于那些使用iOS 5.0或更高版本的人来说,这个答案.现在,AlertView具有用于各种目的的新Property AlertViewStyle.
UIAlertViewStyle
The presentation style of the alert.
typedef enum {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
} UIAlertViewStyle;
Run Code Online (Sandbox Code Playgroud)
例:
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
[alertView release];
Run Code Online (Sandbox Code Playgroud)
代表:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%@",[[alertView textFieldAtIndex:0] text])
}
Run Code Online (Sandbox Code Playgroud)
参考:http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html