简体   繁体   English

为什么UITextField成为firstResponder在我的子viewcontroller中不显示键盘?

[英]why UITextField becomeFirstResponder doesn't show keyboard in my child viewcontroller?

In my first ViewController, I make one UITextField to becomeFirstResponder, and the focus stay that TextField and keyboard appear automatically. 在我的第一个ViewController中,我使一个UITextField成为FirstResponder,重点是TextField和键盘自动出现。 It just works fine. 一切正常。 But then I present another child ViewController which has 3 UITextFields (A,B,C) in this ViewController, I set the first UITextField (say A) to becomeFirstResponder in this child ViewController, the focus stay the A but the keyboard doesn't appear. 但是然后我展示了另一个子ViewController,该子ViewController在此ViewController中具有3个UITextField(A,B,C),我在该子ViewController中将第一个UITextField(例如A)设置为成为FirstResponder,焦点停留在A上,但键盘没有出现。 I searched all the answers the whole day, but nothing found. 我整天都在搜索所有答案,但没有找到任何答案。

Here is the code. 这是代码。

in parent VC, I set: 在父级VC中,我设置:

TestVC *testVC= [[TestVC alloc] init];
testVC.modalPresentationStyle=UIModalPresentationFormSheet;
[detailvc presentViewController:testVC animated:NO completion:nil];

in child VC TestVC, I set: 在子级VC TestVC中,我设置了:

UITextField *v_matcode=[MyViewUtil addTextField:@"" x:10 y:10 width:100 height:40];
[self.view addSubview:v_matcode];
[v_matcode becomeFirstResponder];

and this is the addTextField(): 这是addTextField():

+(UITextField *) addTextField:(NSString *)text x:(int)_x y:(int)_y width:(int)_width height:(int)_height {
  UITextField *v_txt = [[UITextField alloc] init];
  v_txt.frame= CGRectMake(_x, _y, _width, _height);
  v_txt.borderStyle = UITextBorderStyleRoundedRect;
  return v_txt;}

The v_matcode has the focus, but the keyboard doesn't appear. v_matcode具有焦点,但是没有出现键盘。 But if I don't set this textfield becomeFirstResponder and let user tap it,the keyboard appear correctly. 但是,如果我没有将此文本字段设置为FirstResponder并让用户点击它,则键盘会正确显示。 Why is that? 这是为什么?

try setting animated to YES 尝试将动画设置为是

[detailvc presentViewController:testVC animated:YES completion:nil]; [detailvc presentViewController:testVC动画:是完成:无];

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

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