如何弹出文本字段

k20*_*k20 2 iphone sdk ios4

我的应用程序中有一个带有许多标签的视图和带有一些按钮的工具栏.我想按下按钮的同时编辑所有标签.我认为这可能是一种"弹出"文本输入并使键盘同时出现的方法.这是最干净的方法吗?谢谢

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