iPhone 键盘无反应

发布于 2024-11-10 17:48:16 字数 240 浏览 4 评论 0原文

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 技术交流群。

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

发布评论

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

评论(2

旧伤慢歌 2024-11-17 17:48:16

viewDidLoad 中调用 becomeFirstResponder 并不是一个好主意,因为视图甚至可能还没有出现在屏幕上并且还不是视图层次结构的一部分。

尝试在 viewDidAppear: 中调用 becomeFirstResponder

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [txtUsername becomeFirstResponder];
}

Calling becomeFirstResponder in viewDidLoad 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 in viewDidAppear: instead:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [txtUsername becomeFirstResponder];
}
彻夜缠绵 2024-11-17 17:48:16

检查你的 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.

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