Why does the keyboard not show when a view is popped from the navigation stack?

三世轮回 提交于 2019-12-08 08:07:36

问题


I have several UITextField objects on a view. When I press on them, I get a keyboard and the UIKeyboardWillShowNotification event as well. When I push a new view controller on to the stack while one of the text fields is the first responder, the keyboard animates away (as I expected). When I then press the back button, however, they text field becomes the first responder, but the keyboard doesn't come back up. When I click on a different text field in the same view, again, the keyboard fails to come up. It would be fine if the keyboard wasn't up when I reentered the view, but I'm not sure what would make it fail to come up when I click on another text field. Why does this happen, and how can I fix it?

Side note, when I resign first responder before leaving the screen, everything works fine.


回答1:


I have figured it out, and to the best of my understanding this IS a bug with Apple's code. I have a property on one of the parent views of the UITextField that is named firstResponder. There doesn't appear to be any reason why I shouldn't use this name but clearly Apple has already used it somewhere in their code, and when I create a property with this name, it causes the first responder code in the framework to seriously bug out. The solution is to name my property something else.

The only reason resigning first responder was making things work was that I was also setting the firstResponder property to nil.




回答2:


I imagine the keyboard is being hidden by some other mechanism than first responder resigning, so the system thinks it is displaying the keyboard already, and so does not feel the need to show it again.

If you can get a simple example app with a reproducible implementation, it sounds like a bug in iOS which you should report to Apple.



来源:https://stackoverflow.com/questions/8141161/why-does-the-keyboard-not-show-when-a-view-is-popped-from-the-navigation-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!