iOS - UITextView 成为FirstResponder
这就是问题:当 MessageComposeViewController 被解雇时,我的 textView 不会成为第一响应者,键盘也不会出现。为什么?我将 [textViewBecomeFirstResponder]
代码放入 viewWillAppear
中。我该怎么办?
This is the problem : when MessageComposeViewController has been dismissed, my textView doesn't become the first responder and the keyboard doesn't appear. Why? I put the [textView becomeFirstResponder]
code in viewWillAppear
. How can i do??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我后来用这句话调用了“becomeFirstResponder”:
它对我有用。希望这有帮助。
估计是动画的原因吧
I called becomeFirstResponder later by this line:
It worked for me. Hope this help.
I guess it's the animation's reason.
根据 苹果官方文档:
您应该在
viewDidAppear:
中调用[textViewBecomeFirstResponder]
,而不是viewWillAppear:
。似乎您在
[selfmissModalViewControllerAnimated:NO]
中找到的解决方案正在利用注释中的相同规则。According to the Note from the official Apple documentation :
you should call
[textView becomeFirstResponder]
in theviewDidAppear:
instead ofviewWillAppear:
.Seems the solution you have found with
[self dismissModalViewControllerAnimated:NO]
is utilizing the same rule from the note.您的问题不是特别清楚,但您假设当模态视图控制器(我假设您称之为 MessageComposeViewController )被关闭时,会调用
viewWillAppear
。并非所有情况下都会出现这种情况(例如,如果您的视图位于 UINavigationController 内),您可以通过多种方法来处理此问题,但也许最简单的方法是传递您的 MessageComposeViewController 对原始视图控制器的引用并调用一个方法以使您的
UITextField
成为第一响应者。Your question isn't particularly clear, but you have assumed that
viewWillAppear
is called when a modal view controller (what I assume you have called MessageComposeViewController) is dismissed. This may not be the case under all cirumstances (e.g. if your view is inside aUINavigationController
)There are a number of ways you could handle this, but perhaps the simplest would be to pass your MessageComposeViewController a reference to your original view controller and call a method to make your
UITextField
the first responder.我或多或少有相同的问题,它与 segue 处的动画有关,看起来像在不使用 resignFirstResponder 的情况下执行 segue o 关闭视图,破坏与视图的关系,我只是修改 segue 以像这样以编程方式执行此操作:
然后在 viewWillAppear 中我做了下一个:
I have more or less the same problem, it was related with animation at the segue, it looks like doing a segue o dismiss a view without using the resignFirstResponder break the relation with the view, I just modify the segue to doing it programatically like this:
An then in the viewWillAppear I did the next:
迅速
In swift
我找到解决办法了!!!!!!!
因此,在
messageComposeViewController:didFinishWithResult
委托方法中,我们调用[selfmissModalViewControllerAnimated:YES]
,但这是错误的!此方法应该收到 NO,而不是 YES!然后回忆一下[textViewBecomeFirstResponder]
方法!我不知道为什么,但这样该应用程序就可以完美运行!不过还是谢谢大家了! :)
I found the solution!!!!!!!!
So, in the
messageComposeViewController:didFinishWithResult
delegate method we call[self dismissModalViewControllerAnimated:YES]
, but it's wrong! This method should receive NO, not YES! And then recall the[textView becomeFirstResponder]
method! I don't know why, but in this way the app works perfectly!Thanks all however! :)