gpt4 book ai didi

ios - becomeFirstResponder 在 iOS 8 中不起作用

转载 作者:IT王子 更新时间:2023-10-29 08:07:34 27 4
gpt4 key购买 nike

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

 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 中实现吗?

最佳答案

尝试像下面这样调用becomeFirstResponder

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

根据苹果公司的说法,

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.

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.

关于ios - becomeFirstResponder 在 iOS 8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27098097/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com