输入 UITextField 时 iPhone 键盘不出现

发布于 2024-08-30 17:48:25 字数 338 浏览 1 评论 0 原文

这一定是某种我看不到的新手错误,如果您能提供有关检查内容或在哪里查找的提示,我将不胜感激。

我遵循了一个具有 UITextField 的 iPhone 教程,确保我连接了文本字段的 IBOutlet,并且它似乎可以正确编译(没有错误或警告)。但是当我在模拟器下运行它并单击该字段时,我没有得到键盘,因此我无法在该字段中输入任何内容。

我尝试在网站上搜索类似的问题,我发现的只是一些开发人员试图使用多个控制器设置一些复杂的 UI 的问题,其中一个似乎是同一问题,但原始海报只是说他通过启动一个新项目并将代码移植过来解决了这个问题。我想找到一个实际的解决方案,这样当这个问题再次出现时我就不必尝试随机重建项目。

谢谢!

This has to be some kind of newbie blunder that I just can’t see, and I’d be grateful for hints as to what to check or where to look.

I've followed an iPhone tutorial that has a UITextField, making sure I connected the IBOutlet for the text field, and it seems to compile properly (no errors or warnings). But when I run it under the simulator, and click in the field, I don’t get the keyboard, so I can’t enter anything into the field.

I’ve tried searching the site for similar questions, and all I’ve found is a few questions where the developer is trying to set up some complex UI with multiple controllers, and one that seemed to be the same issue, but the original poster simply said that he solved it by starting a new project and porting the code over. I’d like to find an actual solution, so I don’t have to try randomly rebuilding projects when this issue comes up again.

Thanks!

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

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

发布评论

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

评论(5

套路撩心 2024-09-06 17:48:25

为了在解决此问题时涵盖所有基础,请确保不是 iOS 模拟器导致此问题。输入 UITextView 时我也没有看到键盘出现,事实证明模拟器允许您在显示虚拟键盘和仅使用笔记本电脑键盘之间切换。

您可以通过以下方式在两者之间切换:

Hardware > 键盘> 切换软件键盘

或按Cmd + K

(我的来源:https://stackoverflow.com/a/24401535/1700540

所以请确保你没有错误切换模拟器仅使用物理键盘! ...就像我一样

Just to cover all your bases when troubleshooting this, make sure it's not the iOS Simulator that's causing this. I wasn't seeing the keyboard appear when entering a UITextView as well and it turns out the simulator allows you to toggle between displaying the virtual keyboard and just having you use your laptop's keyboard.

You toggle between the two via:

Hardware > Keyboard > Toggle Software Keyboard

or press Cmd + K.

(my source: https://stackoverflow.com/a/24401535/1700540)

So make sure you didn't mistakenly toggle the simulator to only use your physical keyboard! ... like I had

在巴黎塔顶看东京樱花 2024-09-06 17:48:25

确保父容器已选中启用用户交互。仅对单个控件进行检查是不够的。 UIView 可能会无意中取消选择此选项。

您应该检查的一件事是确保包含视图(包含所有控件的 UIView)(即 Interface Builder nib 查看器中的视图图标)已启用用户交互 > 已检查。如果父容器没有选中此选项,即使各个控件选中了此选项,您也会看到此行为。

Make sure parent containers have User Interaction Enabled checked. It is not sufficient for the individual controls to have this checked. The UIView can inadvertently get this deselected.

One thing you should check is to make sure the containing view (the UIView that contains all the controls), which is the View icon in Interface Builder nib viewer, has User Interaction Enabled checked. If the parent container doesn't have this checked, even if the individual controls do, you will see this behavior.

单身情人 2024-09-06 17:48:25

UITextField 的委托连接到什么?您是否确保委托功能,特别是 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
是否返回正确的内容(在本例中为“是”)?

What is the delegate for the UITextField connected to? Have you made sure that the delegate functions, particularly - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
is returning the right thing (in this case YES)?

兮子 2024-09-06 17:48:25

不确定这是否是其他人的问题,但我在以模态方式显示的 TabBar 控制器中使用 TextField,并在主视图控制器中添加了摇动手势。不幸的是,这意味着我在 viewDidLoad 中设置了 [self comeFirstResponder]。在这种情况下,当我的模态视图显示时,它不会成为第一响应者,因此键盘不会显示。

为了解决这个问题,我在调用模态显示之前添加了 [self resignFirstResponder] ,一切又恢复正常了!是的(只花了五天时间就弄清楚了)。

Not sure if this is anyone else's problem but I was using a TextField in a TabBar controller displayed modally and I added the shake gesture in my main view controller. This unfortunately meant I was setting [self becomeFirstResponder] in the viewDidLoad. In that case when my modal view displayed it was not becoming the first responder and hence the keyboard did not display.

To fix it I added [self resignFirstResponder] just prior to calling the modal display and all is well once more! Yay (only took five days to figure that out).

記憶穿過時間隧道 2024-09-06 17:48:25

中声明文本字段,

基本上,您唯一需要做的就是在 .h IBOutlet UITextField *textField

然后在属性

@property (nonatomic, keep) UITextField *textField; 中声明相同的名称;

然后确保您在 .m

@synthesize textField;

中进行合成,然后您必须在界面生成器中链接该字段

Basicly the only thing you need to do is declare the text field in the .h

IBOutlet UITextField *textField

then declare with same name in the property

@property (nonatomic, retain) UITextField *textField;

then make sure you synthesize in the .m

@synthesize textField;

then you have to link the field in the interface builder

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