添加; 不带键盘

我已经创build了一个有UITextField的屏幕。 当我得到一个EditingDidBegin事件时,我resignFirstResponder,调用其中的另一个textField Popover,并为该TextField调用BecomeFirstResponder它。

当它运行时,我得到闪烁插入指针和X清除内容。 虽然没有键盘。 主UIView设置为UserInteractionEnabled:YES。

第一个UITextField的目标行动,它自己的观点。

[textField addTarget:self action:@selector(wantsToEditValue:) forControlEvents:UIControlEventEditingDidBegin]; 

目标操作select器:

 - (IBAction)wantsToEditValue:(id)sender { // set notification so we can update from popover [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saWriteValue:) name:kRefreshFromPopover object:nil]; //we dont want the TagValue textfield to really be the first responder. [textField resignFirstResponder]; [... setup popoverVC, and View. present popover...] 

}

这里是创build第二个UITextField的代码。 这个代码在Popover的VC中

 - (void)viewDidLoad { if (IoUIDebug & IoUIDebugSelectorNames) { NSLog(@"%@ - %@", [self description], NSStringFromSelector(_cmd) ); } [super viewDidLoad]; [self createElementInputControl]; [self createWriteButton]; //We want the input Focus [textFieldInput becomeFirstResponder]; //Resize our view to handle the new width CGRect newViewSize = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, writeButton.frame.origin.x + writeButton.frame.size.width + kWriteElementOffset , self.view.frame.size.height); [self.view setFrame:newViewSize]; } 

创buildinput代码:

 -(void) createElementInputControl { textFieldInput = [[UITextField alloc] initWithFrame:CGRectMake( kWriteElementOffset , kWriteElementHeightOffset, kTagValueInputInitialWidth, kWriteElementDefaultHeight)]; textFieldInput.borderStyle = UITextBorderStyleRoundedRect; textFieldInput.clearButtonMode = UITextFieldViewModeWhileEditing; textFieldInput.textAlignment = UITextAlignmentLeft; [textFieldInput setDelegate:self]; [textFieldInput setKeyboardType:UIKeyboardTypeDefault]; // Set the value of the text [textFieldInput setText:self.myTag.value]; CGSize textFieldInputSize = [textFieldInput.text sizeWithFont:textFieldInput.font]; //Set the Button Width [textFieldInput setFrame:CGRectMake(textFieldInput.frame.origin.x, textFieldInput.frame.origin.y, textFieldInputSize.width + kTagValueInputWidthBuffer, textFieldInput.frame.size.height)]; [self.view addSubview:textFieldInput]; } 

当我删除becomeFirstResponder代码时,popup窗口正常,虽然没有闪烁的插入指针。 我点击字段,我得到插入指针,X清除内容button,是的一个键盘。

我想键盘显示,而不必点击新的文本字段。

谢谢!

为了成为第一响应者,视图必须位于视图层次结构中。 你需要添加你的textFieldInput作为子视图的东西。

根据UIResponder中的Apple文档:

你可以调用这个方法来创build一个响应者对象,比如查看第一个响应者。 但是,如果它是视图层次结构的一部分,则只能在该视图上调用它。 如果视图的窗口属性包含一个UIWindow对象,则它已经安装在视图层次结构中; 如果返回nil,则视图将从任何层次结构中分离出来。

当你调用didBeginEditing成为第一响应者时,你会遇到一个无限循环。原因是,当你调用becomeFirstResponder时,它会调用didBeginEditing。 所以它解释了光标闪烁和你的陈述

当我删除becomeFirstResponder代码时,popup窗口正常,虽然没有闪烁的插入指针。 我点击字段,我得到插入指针,X清除内容button,是的一个键盘。

为了解决你的问题,

在beginEditingMethod中,

 if(texfield.tag == firstTextFieldTag) { //Create second TextField and make it become first responder } else { // do want you want in the beginEditing of your second textfield. }