0
在我的第一個ViewController中,我讓一個UITextField成爲FirstResponder,焦點保持TextField和鍵盤自動出現。它工作正常。但後來我提出了另一個子ViewController,它有3個UITextFields(A,B,C)在這個ViewController中,我設置第一個UITextField(比如說A)在這個子ViewController中成爲FirstResponder,焦點停留在A但鍵盤沒有出現。我整天搜索了所有的答案,但沒有發現。爲什麼UITextField becomeFirstResponder在我的子視圖控制器中不顯示鍵盤?
這是代碼。
父VC,我設置:
TestVC *testVC= [[TestVC alloc] init];
testVC.modalPresentationStyle=UIModalPresentationFormSheet;
[detailvc presentViewController:testVC animated:NO completion:nil];
兒童VC TestVC,我設置:
UITextField *v_matcode=[MyViewUtil addTextField:@"" x:10 y:10 width:100 height:40];
[self.view addSubview:v_matcode];
[v_matcode becomeFirstResponder];
,這是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;}
的v_matcode有重點,但沒有出現鍵盤。但是,如果我不設置此文本字段成爲FirstResponder,並讓用戶點擊它,則鍵盤顯示正確。這是爲什麼?
「addTextField:」代碼是什麼樣的?到目前爲止,它看起來像是在做所有正確的事情,但是「addTextField:'是一些自定義方法,所以它可能會做些古怪的事情。 –
我同意@ michael-dautermann,你可以請發佈「addTextField:」方法的代碼,這可以幫助。 – 8Ours
現在無法測試它,但嘗試將調用包裝爲dispatch_async(dispatch_get_main_queue(),^ {/ * call here * /})內的becomeFirstResponder; –