为什么 presentModalViewController 会阻碍 UITextField 响应?

发布于 2024-08-22 10:07:31 字数 339 浏览 11 评论 0原文

我添加到从另一个视图控制器使用 presentModalViewController:animated: 呈现的视图的任何 uitextfield 都不会响应任何触摸事件(例如点击 uitextfield 时键盘不会显示),如果我使用 < code>[textField成为FirstResponder]强制键盘显示,唯一有效的时候是在视图控制器的viewDidLoad方法中

任何人都知道为什么uitextfield在我使用时没有响应presentModalViewController:animated: 显示 uitextfield 所在的视图控制器?

Any uitextfield I add to a view which is presented from another view controller with presentModalViewController:animated: does not respond to any touch events (like the keyboard doesnt display when the uitextfield is tapped) also if i use [textField becomeFirstResponder] to force the keyboard to display, the only time this works is in the viewDidLoad method of the view controller

Anyone know why the uitextfield is not responsive whatsoever when i use presentModalViewController:animated: to display the view controller which the uitextfield is on?

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

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

发布评论

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

评论(2

谁的年少不轻狂 2024-08-29 10:07:31

这个问答很旧,但我刚刚注意到以模态方式呈现的 UIWebView (带有输入字段)的相同行为,并找到了一个解决方法来保留

- (BOOL)canBecomeFirstResponder {    
    return YES; 
}

如果此方法被删除或 返回 NO< /code>,键盘显示正确(如 DotSlashSlash 所指出的),但将其放在

[self resignFirstResponder];

前面会获得相同的结果

[self presentModalViewController:aViewController animated:animated];

This Q&A is old, but I have just noticed the same behaviour with a UIWebView (with input fields) presented modally and found a workaround to preserve

- (BOOL)canBecomeFirstResponder {    
    return YES; 
}

If this method is removed or return NO, the keyboard shows up correctly (as pointed out by DotSlashSlash), but the same result is obtained putting

[self resignFirstResponder];

just before

[self presentModalViewController:aViewController animated:animated];
魄砕の薆 2024-08-29 10:07:31

经过很多麻烦,我发现它

-(BOOL)canBecomeFirstResponder {    
    return YES; 
}

隐藏在我的代码中的某个地方,由于某种原因,如果我通过 PresentModalViewController:animated: 方法添加视图,则不允许文本字段成为第一响应者

after much trouble i came to find that

-(BOOL)canBecomeFirstResponder {    
    return YES; 
}

was hidden in my code somewhere, this for some reason was not allow the textfield to become first responder if i added the view via the presentModalViewController:animated: method

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