UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_NAME
message:@"Please enter amount"
delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 2;
[alert show];
以上是我在UIAlertView中的编码和类型数量。当键盘出现时,我的客户想要"完成"按钮而不是"返回"。请帮我怎么做?
答案 0 :(得分:3)
试试这个
<强> UIAlertView中强>
<强>目标C 强>
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: APP_NAME message:@"Please enter amount" delegate:self cancelButtonTitle:@"Done" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeNumberPad;
// set return key type of current textfield
textField.returnKeyType = UIReturnKeyDone;
[alert show];
<强>夫特强>
var alert: UIAlertView = UIAlertView(title: APP_NAME, message: "Please enter amount", delegate: self, cancelButtonTitle: "Done", otherButtonTitles: "")
alert.alertViewStyle = .PlainTextInput
var textField: UITextField = alert.textFieldAtIndex(0)
textField.keyboardType = .NumberPad
textField.returnKeyType = UIReturnKeyDone
alert.show()
另一种类型的枚举
typedef NS_ENUM(NSInteger, UIReturnKeyType) {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),
};
注意 - UIAlertView已被弃用,因为iOS 8在这个地方使用
UIAlertcontroller
<强> UIAlertController 强>
<强>夫特强>
var loginTextField: UITextField?
let alertController = UIAlertController(title:APP_NAME, message: "Please enter amount", preferredStyle: .Alert)
let ok = UIAlertAction(title: "Done", style: .Default, handler: { (action) -> Void in
print("Ok Button Pressed")
})
alertController.addAction(ok)
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
// Enter the textfiled customization code here.
loginTextField = textField
//loginTextField?.placeholder = "xxx"
loginTextField?.keyboardType = UIKeyboardType.NumberPad
loginTextField?.returnKeyType = UIReturnKey.Done
}
presentViewController(alertController, animated: true, completion: nil)
<强>目标C 强>
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:APP_NAME
message:@"Please enter amount"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *Done = [UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
// handler code
}];
[alertController addAction:Done];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//handler code
textField.keyboardType = UIKeyboardTypeNumberPad;
// set return key type of current textfield
textField.returnKeyType = UIReturnKeyDone;
}];
[self presentViewController:alertController animated:YES completion:nil];
答案 1 :(得分:1)