本文介绍了resignFirstResponder不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在iPad上隐藏键盘,但我不知道为什么resignFirstResponder不起作用。
但是popToRoot运行良好。

I try to hide keyboard on iPad but I don't know why resignFirstResponder don't work.But popToRoot has work well.

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
    NSString *desc = [NSString stringWithFormat:@"%@",[descTF text]];
    [textField resignFirstResponder];
    [self.navigationController popToRootViewControllerAnimated:YES];


    return YES;
}

那么你能指导一下我该怎么办?

So Could you guide me what should I do please ??

推荐答案

这个字段是否在 UIModalPresentationFormSheet 中?如果是这样,这是一个已知的问题,你不能以编程方式解除键盘,直到视图控制器被解除。

Is this field inside a UIModalPresentationFormSheet? If so, it's a known issue that you can not dismiss the keyboard programmatically until the view controller gets dismissed.

更新:根据此主题,可能的解决方法是从内部呈现工作表视图控件实现disablesAutomaticKeyboardDismissal方法的导航控制器子类。所以类似于:

UPDATE: according to this thread from the Apple Developer Forums, a possible workaround for this is to present the sheet view control from inside a navigation controller subclass that implements the disablesAutomaticKeyboardDismissal method. So something like:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
CustomNavigationController *navController = [[CustomNavigationController alloc] initWithRootViewController:myViewController];
theNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:theNavigationController animated:YES];

这篇关于resignFirstResponder不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:02