入力スタイルを表示する場合は、まずクラスにUIAlertViewDelegateを実装します。
次に、alertView を提示するときに、デリゲートを自分自身に設定します。
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
})