becomeFirstResponder在iOS 8中不起作用 [英] becomeFirstResponder not working in iOS 8

查看:334
本文介绍了becomeFirstResponder在iOS 8中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UITextField的方法becomeFirstResponder来显示键盘。
这适用于iOS 7.但在iOS 8中,此方法不显示键盘。

I am using UITextField's method becomeFirstResponder to show the keyboard. This is working in iOS 7. But in iOS 8 this method doesn't show the keyboard.

 UITextField *txtAddNew = [[UITextField alloc] initWithFrame:CGRectMake(10,10,240, 21)];
 txtAddNew.font = [UIFont fontWithName:@"Helvetica" size:16];
 txtAddNew.clearButtonMode = UITextFieldViewModeWhileEditing;
 txtAddNew.returnKeyType = UIReturnKeyDone;
 txtAddNew.delegate = self;
 txtAddNew.autocorrectionType = UITextAutocorrectionTypeNo;
 txtAddNew.tag = 15;

 // Open keyboard
 [txtAddNew becomeFirstResponder];

在iOS 8中有什么办法吗?

Is there any way to do it in iOS 8?

推荐答案

尝试按下面的方式调用 becomeFirstResponder

Try calling becomeFirstResponder like below

[txtAddNew performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];

根据Apple,


如果当前
响应者可以辞退第一响应者状态(canResignFirstResponder)
并且新响应者可以成为第一响应者,则响应者对象仅成为第一响应者。

A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.

您可以调用此方法来创建响应者对象,例如查看
第一响应者。但是,如果
是视图层次结构的一部分,则只应在该视图上调用它。如果视图的window属性包含
UIWindow对象,则它已安装在视图层次结构中;如果
返回nil,则视图将从任何层次结构中分离。

You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.

这篇关于becomeFirstResponder在iOS 8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆