Iphone 如何弹出文本字段
我的应用程序中有一个带有许多标签的视图和一个带有一些按钮的工具栏。我想在按下按钮时同时编辑所有标签。我想这可能是一种“弹出”文本输入并同时显示键盘的方法。哪种方法最干净? 谢谢 或者。我是这样做的:Iphone 如何弹出文本字段,iphone,ios4,sdk,Iphone,Ios4,Sdk,我的应用程序中有一个带有许多标签的视图和一个带有一些按钮的工具栏。我想在按下按钮时同时编辑所有标签。我想这可能是一种“弹出”文本输入并同时显示键盘的方法。哪种方法最干净? 谢谢 或者。我是这样做的: UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Please enter your name:" message:@"\n\n"
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];
然后在UIAlertView委托方法中,从textField.text:-)读取内容。这组代码可能会有所帮助
我知道这个答案太晚了,但这个答案适合那些使用iOS 5.0或更高版本的用户。 现在,AlertView具有用于各种用途的新属性AlertViewStyle
UIAlertViewStyle
The presentation style of the alert.
typedef enum {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
} UIAlertViewStyle;
例如:
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
[alertView release];
代表:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%@",[[alertView textFieldAtIndex:0] text])
}
参考资料:@Nevin非常感谢您的推荐,非常简单(对于Iphone来说就是如此!),只要您想到它。但是,我必须修正一个输入错误,行[prompt textField];应该是[prompt addSubview:textField]@谢谢!:-)不适用于ios7,是否有任何解决方案,我需要3个字段,旧传递、新传递、确认传递,我使用了此功能,但我们需要像上面一样进行自定义,typedef enum{UIAlertViewStyleDefault=0,UIAlertViewStyleSecureTextInput,UIAlertViewStylePlainTextInput,UIAlertViewStyleLoginAndPasswordInput}UIAlertViewStyle;我不知道,这太棒了!一个链接到一个可能以后(比如现在)不起作用的站点的答案是没有用的