我正在使用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中有什么方法可以做到吗?
发布于 2014-11-24 05:12:40
尝试按下面的方式调用becomeFirstResponder
[txtAddNew performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];按照苹果的说法,
只有当当前响应者可以辞职第一响应者状态(canResignFirstResponder)并且新的响应者可以成为第一响应者时,响应对象才会成为第一响应者。 您可以调用此方法使响应器对象(如视图)成为第一个响应程序。但是,只有当该视图是视图层次结构的一部分时,才应该对其进行调用。如果视图的window属性包含一个UIWindow对象,则它已安装在视图层次结构中;如果它返回零,则该视图将与任何层次结构分离。
发布于 2016-12-19 09:29:23
Swift 3
这是被接受的答案的快速3版本。为了让它开始工作,我还得加点时间。
txtAddNew.perform(
#selector(becomeFirstResponder),
with: nil,
afterDelay: 0.1
)发布于 2014-11-24 05:16:28
我想你错过了addsubview the txtAddNew to the Mainview
txtAddNew.tag = 15;
[self.view addsubview:txtAddNew];
// Open keyboard
[txtAddNew becomeFirstResponder];https://stackoverflow.com/questions/27098097
复制相似问题