如果您想呈现输入样式,首先在您的类中实现UIAlertViewDelegate 。
其次,当您展示 alertView 时,将委托设置为 self。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"a" message:@"b" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"aaa", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];'
如果您想更改特定字段的键盘类型,请这样做
例如,对于第一个字段,它将使键盘数字化。
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
iOS 8.0 Swift 更新
从 ios 8.0 起 UIAlertView
已弃用,因此您可能需要使用UIAlertController
var alert = UIAlertController(title: "Title", message: "Your msg",
preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel,
handler:yourHandler))
alert.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Password"
textField.secureTextEntry = true // setting the secured text for using password
textField.keyboardType = UIKeyboardType.Default
})