ios - 隐藏类型为 UIKeyboardTypeNumberPad objective c 的键盘

标签 ios iphone objective-c delegates uikeyboardtype

<分区>

在 iPhone 应用程序中,我有一个需要输入数字的 UITextField,因此我将键盘类型作为 UIKeyboardTypeNumberPad 传递。它可以工作,但没有返回或完成按钮,所以我该如何隐藏键盘。

引用代码为:

textDriverAge.delegate=self;
textDriverAge.keyboardType=UIKeyboardTypeNumberPad;
textDriverAge.clearButtonMode = UITextFieldViewModeWhileEditing;
[textDriverAge setReturnKeyType:UIReturnKeyDone];// UIReturnKeyNext];
textDriverAge.enablesReturnKeyAutomatically=TRUE;

我已经处理了 UITextfield 事件,例如:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {


if(textDriverAge == textField)
{
    [textDriverAge resignFirstResponder];

    //[tglDropInDropOff becomeFirstResponder];
}

}

指导我如何隐藏键盘。

最佳答案

你可以使用两种类型

  1. 触摸方法

    使用此链接 iOS dismissing keyboard, UILabel malfunction

在另一种选择中,在您的 View Controller 中添加 UIToolbar

- (void)viewDidLoad

{
[super viewDidLoad];

UIToolbar  *numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad:)],
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad:)],
                       nil];
yourtextField.inputAccessoryView = numberToolbar;

 }


- (IBAction)cancelNumberPad:(UITextField*)textField
{
 [yourtextField resignFirstResponder];
    yourtextField.text=@"";
}


- (IBAction)doneWithNumberPad:(UITextField*)textField 
{
[yourtextField resignFirstResponder];
}

关于ios - 隐藏类型为 UIKeyboardTypeNumberPad objective c 的键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23752578/

相关文章:

ios - 如何从Objective C中的另一个类正确访问变量

ios - 核心图中记录的最大限制

iOS。配置 flurry 以在我的具体应用程序中显示广告?

ios - 使用 Titanium 或 Rhodes 重写原生 iOS 应用程序

ios - 使用带有 UIViewController 的 Xcode 5 停止 [tableView loadData] 取消选择行

iphone - 在推送 UINavigationController 时为 UIView 设置动画

iphone - 是否有比 GKSession 更可靠的替代方案,允许 3 个以上设备之间进行 P2P?

javascript - event.touches 始终未定义

objective-c - 为什么在检索 intValue 时要转换 NSMutableArray 的 NSNumber 内容?

ios - 获取 interactivePopGestureRecognizer 关闭回调/事件