键盘没有响应resignFirstResponder [英] keyboard not responding to resignFirstResponder

查看:300
本文介绍了键盘没有响应resignFirstResponder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当选择textField时,我想显示一个弹出视图,而不是显示键盘(我的代码位于底部)。如果键盘没有显示,那么一切都很好。但是,如果键盘正在显示然后选择了文本字段,键盘就不会被解雇,某个地方的第一个响应者必须迷路但我不知道在哪里。有人有解决方案吗?

Instead of showing the keyboard I want to display a popover view when a textField is selected (my code is at the bottom). If the keyboard isn't showing then everything works great. However, if the keyboard is showing and then the textfield is selected the keyboard doesn't get dismissed, somewhere the firstResponders must be getting lost but I don't know where. Does anyone have a solution to this?

我的文本字段:

    self.startDateTextField = [[UITextField alloc] initWithFrame:CGRectMake(79, 148, 138, 27)];
[self.startDateTextField setBorderStyle:UITextBorderStyleRoundedRect];
[self.startDateTextField setDelegate:delegate];
[self.startDateTextField addTarget:delegate action:@selector(editStartDate:) forControlEvents:UIControlEventEditingDidBegin];
[popoverWrapper addSubview:self.startDateTextField];

editStartDate:我有:

-(void)editStartDate:(UITextField *)textField {

[textField resignFirstResponder];

DatePickerVC *datePickerVC = [[DatePickerVC alloc] init];
datePickerVC.delegate = self;

self.popoverController = [[UIPopoverController alloc] initWithContentViewController:datePickerVC];
[self.popoverController setDelegate:self];

[self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 5, 5) inView:textField permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}


推荐答案

这很容易做到,使用你的UITextFieldDelegate方法特别是UITextFieldShouldBeginEditing并返回NO并执行代码来显示popover。通过这种方式,键盘永远不会显示。

This is very easy to do, use your UITextFieldDelegate methods specifically UITextFieldShouldBeginEditing and return NO and execute the code to show the popover instead. This way the keyboard is never shown to begin with.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  [self.view endEditing:YES]; // added this in for case when keyboard was already on screen
  [self editStartDate:textField];
  return NO;
}

要使其工作,请确保将textField的委托设置为self(视图控制器)并在您的editStartDate方法中删除resignFirstResponder调用。

for it to work make sure you set the delegate of the textField to self (the view controller) and in your editStartDate method remove the resignFirstResponder call.

这篇关于键盘没有响应resignFirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆