ios - 在 objective-c 中隐藏键盘

标签 ios iphone objective-c keyboard

我在一个 View 中有几个文本字段,其中一个用于写国家。
我希望当您在 testField country 中向上按时,您可以在另一个 View 中使用 UIPickerView 来选择国家/地区。
然后放置以下与 _tfCountry 的事件“Editing did begin”关联的代码。

- (IBAction)countryPressed:(id)sender {
    [_tfCountry endEditing:YES];

    [_tfAdress  resignFirstResponder];
    [_tfCountry  resignFirstResponder];
    [_tfName  resignFirstResponder];
    [_tfEmail  resignFirstResponder];
    [_tfTelephone  resignFirstResponder];
    [_tfTaxID  resignFirstResponder];

    [self save];
    _picker = [self.storyboard instantiateViewControllerWithIdentifier:@"PickerCountry"];
    _picker.delegate = self;

    [self.navigationController pushViewController:_picker animated:YES];
}

但是键盘并没有像它应该的那样消失。
他停留在屏幕上并点击下一个 View 的按钮。

他不应该放弃“resignFirstResponder”?
我做错了什么?

我努力

[self.view endEditing:YES]

并没有奏效。

如果我评论改变 View 的部分,键盘不会消失但会停止向文本字段发送数据

最佳答案

尝试延迟隐藏它。

    [self performselector:@selector(hideKB) withObject:nil afterDelay:0.1];


  -(hideKB){

   [_tfAdress  resignFirstResponder];
   [_tfCountry  resignFirstResponder];
   [_tfName  resignFirstResponder];
   [_tfEmail  resignFirstResponder];
   [_tfTelephone  resignFirstResponder];
   [_tfTaxID  resignFirstResponder];
    }

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

相关文章:

ios - 没有找到与 RestKit 的可映射关系值 keyPath

ios - 在 Objective-C 中获取时间

ios - 使用平移、旋转和捏合手势编辑后如何保存 UIImage

iphone - 网站上的 Twitter feed 无法在 iPad、iPhone 和类似设备上运行

ios - 从操作内部访问队列

iphone - 在 tableView 中删除行时出现核心数据错误

iphone - 无法将应用内购买添加到此版本,因为它已提交审核。

iphone - Objective-C 私有(private)方法困境

ios - UICollectionView 拖拽移除半透明单元格

ios - 在 cocos2d v3 中创建填充图像图案的图层的最简单方法