故障排除成为FirstResponder 不为某些用户显示键盘

发布于 2024-12-20 22:25:38 字数 1071 浏览 1 评论 0原文

我得到了一个 TextView,它应该在按下按钮时显示,并让用户通过键盘输入文本。

- (IBAction) changeName {

    changeNameBtn.hidden = YES;
    backBtn.hidden = YES;

    usernameLabel.hidden = NO;
    inputTextField.hidden = NO;
    [inputTextField becomeFirstResponder]; // to show keyboard
}

这对我们大多数人来说都很好。

但是对于我的一些测试人员来说,在地理位置较远的位置,键盘无法显示。如何解决这个问题?我们的设备表现不同的原因可能是什么?它对我和其他人来说都很好用。我们都使用相同的设备(iPod、iOS 4.1 - 5.1)。

我尝试的第一件事不起作用:

我猜测在becomeFirstResponder被触发之前,inputTextField确实以某种方式没有及时变得可见,所以我添加了setNeedsDisplay< /code> 因为我认为这会强制更新。

[inputTextField setNeedsDisplay];
[inputTextField becomeFirstResponder];

我尝试的第二件事不起作用:

if([inputTextField canBecomeFirstResponder]){
    [inputTextField becomeFirstResponder];
}

我尝试的第三件事是一种解决方法,要求不幸的用户按下该字段:

- (IBAction) inputTextFieldTouch {
    [inputTextField becomeFirstResponder];
}

此解决方法有效,但必须有更好的方法。请告诉我我做错了什么! :) 以及如何解决这样的问题而不能够自己复制它?

I got a TextView that is supposed to show upon a button press, and let the user enter text through the keyboard.

- (IBAction) changeName {

    changeNameBtn.hidden = YES;
    backBtn.hidden = YES;

    usernameLabel.hidden = NO;
    inputTextField.hidden = NO;
    [inputTextField becomeFirstResponder]; // to show keyboard
}

This works fine for most of us.

But the Keyboard does not show for some of my testers, at a geographically remote location. How to trouble shoot this? And what could be the reason for the different behavior of our devices? It works fine for me and everybody else. We all use the same devices (iPod, iOS 4.1 - 5.1).

First thing I tried did not work:

I guessed that the inputTextField did in some way not become visible in time, before becomeFirstResponder was fired, so I added setNeedsDisplay as I thought that would force an update.

[inputTextField setNeedsDisplay];
[inputTextField becomeFirstResponder];

Second thing I tried did not work:

if([inputTextField canBecomeFirstResponder]){
    [inputTextField becomeFirstResponder];
}

Third thing I tried is a workaround, requiring the unlucky user to press the field:

- (IBAction) inputTextFieldTouch {
    [inputTextField becomeFirstResponder];
}

This workaround works, but there must be a better way. Please enlighten me about what I am doing wrong! :) And how to approach issues like this without being able to duplicate it myself?

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

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

发布评论

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

评论(5

葬シ愛 2024-12-27 22:25:38

我稍后通过这行代码调用了 becomeFirstResponder

[self.searchBar performSelector:@selector(becomeFirstResponder) 
                     withObject:nil 
                     afterDelay:0.1f];

它对我有用。希望这有帮助。

I called becomeFirstResponder later by this line:

[self.searchBar performSelector:@selector(becomeFirstResponder) 
                     withObject:nil 
                     afterDelay:0.1f];

It worked for me. Hope this help.

蓝天白云 2024-12-27 22:25:38

当您尝试使其成为第一响应者时,文本视图尚未完成绘制。

您可以尝试对外观进行动画处理并在完成块中设置第一响应者。

[UIView animateWithDuration:0.0 animations:^{
   [view addSubview:textView];
} completion:^(BOOL finished){
   [textView becomeFirstResponder];
}];

The textview has not finished being drawn by the time you try to make it the first responder.

You can try animating the appearance and setting the first responder in the completion block.

[UIView animateWithDuration:0.0 animations:^{
   [view addSubview:textView];
} completion:^(BOOL finished){
   [textView becomeFirstResponder];
}];
日记撕了你也走了 2024-12-27 22:25:38

从iOS8开始,在UITextView上调用becomeFirstResponder不会在iOS模拟器上显示键盘,但在真实设备上会显示键盘。因此,请务必使用实际设备进行检查。但这在 iOS7 上不会发生。

As of iOS8, calling becomeFirstResponder on a UITextView doesn't show the keyboard for me on the iOS simulator, but it does on the real device. So be sure to check it with an actual device. This doesn't happen on iOS7 though.

落叶缤纷 2024-12-27 22:25:38

如果有人偶然发现这个问题并且您在应用程序中使用了多个UIWindow - 请确保您想要的UIWindow,即您所在的元素启用第一响应者是 isKeyWindow == true。如果没有 - 对其调用 makeKeyAndVisible()

In case anyone stumbles upon this question AND you are using multiple UIWindows in your app - make sure your desired UIWindow, where the element you are making first responder on, is isKeyWindow == true. If not - call makeKeyAndVisible() on it.

清引 2024-12-27 22:25:38

先尝试看看是否可以显示键盘:

if([inputTextField canBecomeFirstResponder]){
    [inputTextField becomeFirstResponder];
}

Try to see if you can show the keyboard first:

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