简体   繁体   English

UITextField无法响应触摸或将不会变为活动状态

[英]UITextField not responding to touches or will not become active

I added a UITextField to my storyboard: 我在故事板上添加了一个UITextField:

@property (weak, nonatomic) IBOutlet UITextField *nameField;

And it was working fine at first, but had some constraint issues which caused the view to not build correctly on an iPhone 5. So I messed with some of the constraints to get it to display correctly and now the keyboard never comes up/the UITextField refuses to respond to touches OR become active. 一开始它运行良好,但是存在一些约束问题,导致视图无法在iPhone 5上正确构建。因此,我搞砸了一些约束,以使其能够正确显示,现在键盘再也无法启动/ UITextField拒绝响应触摸或变得活跃。

I tried setting a UITapGestureRecognizer to the nameField, didn't work. 我尝试将UITapGestureRecognizer设置为UITapGestureRecognizer ,但不起作用。

I made sure there were no views blocking it (checked on the view debugger, and then explicitly called [self.view bringSubviewToFront:self.nameField]; in viewDidAppear ) 我确保没有任何视图阻止它(在视图调试器上检查,然后在viewDidAppear显式调用[self.view bringSubviewToFront:self.nameField];

I tried [self.nameField setUserInteractionEnabled:YES]; 我试过[self.nameField setUserInteractionEnabled:YES]; as well because why not. 以及因为为什么不这样。

So then I went to the storyboard, clicked on the text field and under the connection tab on the right side menu I looked at "Sent Events" and hooked up Touch Up Inside to an IBAction method: 因此,然后转到情节提要,单击文本字段,然后在右侧菜单的连接选项卡下,查看“已发送事件”,并将Touch Up Inside连接到IBAction方法:

- (IBAction)beginNameEdit:(id)sender {
    NSLog(@"Edit begin");
    BOOL accepted = [self.nameField becomeFirstResponder];
    if (accepted) {
        NSLog(@"accepted");
    }
}

Nothing happens, (Edit begin did not print). 没有任何反应,(未打印开始编辑)。 (I touched up inside the boundary as well for sure, but whatever) (我也确实在边界内进行了润色,但是无论如何)

So then I hooked up Touch Down to the same exact IBAction. 因此,我将Touch Down连接到了相同的IBAction。

This time, I started getting 'Edit begin' to print but the call to become first responder did nothing despite accepted actually getting printed (which means that according to Apple, the text field accepted first responder status) 这次,我开始打印“开始编辑”,但尽管已接受实际打印,但成为第一响应者的电话却什么也没做(这意味着根据苹果的说法,文本字段接受了第一响应者的状态)

I can't seem to make my textField active and so it's forever stuck on showing the placeholder text... It makes no sense, especially because I would be shocked if playing with some of the auto layout constraints could have any sort of effect. 我似乎无法使我的textField处于活动状态,因此它永远都停留在显示占位符文本上……这没有任何意义,尤其是因为如果使用某些自动布局约束可能会产生某种效果,我会感到震惊。

Any suggestions? 有什么建议么?

Ok, and in classic the-answer-is-the-last-thing-you'd-expect fashion: 好的,用经典的答案是你期待的方式:

I was using the simulator to test the app. 我正在使用模拟器来测试应用程序。 Turns out the keyboard doesn't always come up when you're using the simulator because it auto-detects the fact you have an ACTUAL keyboard on the computer you are using. 原来,当您使用模拟器时,键盘并非总是会出现,因为它会自动检测到您正在使用的计算机上有ACTUAL键盘的事实。 So instead of a keyboard coming up on the simulator it was silently becoming the first responder and waiting for me to type something on my computer's keyboard. 因此,模拟器没有出现键盘,而是默默地成为了第一响应者,等待着我在计算机键盘上键入内容。

Why the keyboard was coming up earlier and not now, I have no clue. 为什么键盘较早出现而不是现在出现,我不知道。 But I'll leave this up in case anyone else comes across this issue. 但是,如果其他任何人遇到此问题,我将不予理会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM