becomeFirstResponder 在 iOS 8 中不起作用 [英] becomeFirstResponder not working in 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
[txtAddNew performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];
根据 Apple 的说法,
As per 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屋!