iPhone 键盘无反应
在 viewdidload
方法中,我通过以下方式将其中一个文本字段指定为第一响应者。
[txtUsername becomeFirstResponder];
加载视图后,文本字段将变为活动状态并出现键盘。但是当我尝试在键盘上打字时,它没有响应。但是,当我触摸文本字段时,键盘可以正常响应。我不知道这有什么问题。谁能给我一个建议吗?
提前致谢 - 阿比拉什
In the viewdidload
method, I've assigned one of my text fields as first responder by the following way.
[txtUsername becomeFirstResponder];
When the view gets loaded, the text field becomes active and a keyboard appears. But when I tried typing on the keyboard, it is not responding. However when I touched the text field, the keyboard is responding properly. I don't know what is wrong with this. can anyone give me a suggestion?
Thanks in Advance - Abilash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
viewDidLoad
中调用becomeFirstResponder
并不是一个好主意,因为视图甚至可能还没有出现在屏幕上并且还不是视图层次结构的一部分。尝试在
viewDidAppear:
中调用becomeFirstResponder
:Calling
becomeFirstResponder
inviewDidLoad
is not a good idea because the view might not even be on the screen and part of the view hierarchy yet.Try calling
becomeFirstResponder
inviewDidAppear:
instead:检查你的 viewDidLoad 中是否有任何 Outlets 的构造,可能是其中一些在你将 tetUsername 设置为第一响应者后被调用。
Mike Weller 的回答也是此类问题最常见的情况。
check if there's any construction of Outlets in your viewDidLoad, may be some of them is called after you set tetUsername as first responder.
Also Mike Weller's answer is the most common situation of such problem.