resignFirstResponder 无法在模态视图控制器中工作

发布于 2024-10-08 07:14:31 字数 781 浏览 5 评论 0原文

我在使用 UIModalPresentationFormSheet 显示的视图中放弃键盘时遇到问题。当我使用 UIModalPresentationPageSheet 时,它工作正常(键盘隐藏)。这是我非常简单的代码,它显示模式视图,一个在表单中,一个在页面表中。

- (void)showModalWithFormSheet:(BOOL)formSheet {
  testViewController *test = [[testViewController alloc] initWithNibName:nil bundle:nil];
  test.modalPresentationStyle = formSheet ? UIModalPresentationFormSheet : UIModalPresentationPageSheet;
  [self presentModalViewController:test animated:YES];
  [test release]; 
}

这是一个退出响应者的 textField 委托。

- (BOOL)textFieldShouldReturn:(UITextField *)t {
  [t resignFirstResponder];
  return YES;
}

相同的代码,但当以表单形式呈现时,我无法隐藏键盘(调用 resignFirstResponder 后)。我在模拟器和设备上都尝试过这个。任何帮助将不胜感激,这完全让我发疯!很难相信这个问题以前没有被提出过,我是不是错过了什么?

谢谢莹

I'm having an issue with resigning the keyboard in a view that is shown using UIModalPresentationFormSheet. It works fine(keyboard hides) when I use UIModalPresentationPageSheet. Here is my very simple code that brings up the modal view, one in form sheet, and one in page sheet.

- (void)showModalWithFormSheet:(BOOL)formSheet {
  testViewController *test = [[testViewController alloc] initWithNibName:nil bundle:nil];
  test.modalPresentationStyle = formSheet ? UIModalPresentationFormSheet : UIModalPresentationPageSheet;
  [self presentModalViewController:test animated:YES];
  [test release]; 
}

Here is a textField delegate that resigns the responder.

- (BOOL)textFieldShouldReturn:(UITextField *)t {
  [t resignFirstResponder];
  return YES;
}

Identical code, but when presented as a formsheet, i cannot get the keyboard to hide(after resignFirstResponder is called). I tried this on both simulator and device. Any help would be appreciated, this is totally driving me insane! Its hard to believe that this question has not been brought up before, am i missing something?

Thanks

Ying

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-10-15 07:14:32

此处回答。只是你下面的一些帖子。

Answered here. Just some posts under yours.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文