2012-02-10 3 views
2

私はUITextFieldを持つ画面を作成しました。私はEditingDidBeginイベントを取得すると、私はresignFirstResponder、その中の別のtextFieldでPopoverを持ち上げ、そのTextFieldに対してBecomeFirstResponderを呼び出します。[myUITextField becomeFirstResponder]を追加する。キーボードを表示しない

実行すると、点滅挿入ポインタとXクリアコンテンツが表示されます。キーボードはありません。 Master UIViewはUserInteractionEnabled:YESに設定されています。

最初のUITextFieldのtargetアクションは、それ自身のビュー上にあります。

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

ターゲットアクションセレクタ:

- (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...] 

}

ここでは、第2のUITextFieldを作成するためのコードです。

-(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コードを削除すると、ポップオーバーはなし点滅挿入ポインタしかし、通常通りに出てくる:このコードは

- (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]; 
} 

は、入力コードを作成します。..ポップオーバーのためのVCです。私はフィールドをタップ、私は挿入ポインタ、Xクリアコンテンツボタン、そしてはいキーボードを取得します。

新しいテキストフィールドをクリックすることなくキーボードを表示したいです。

ありがとうございます!

答えて

1

最初の応答者になるためには、ビューはビュー階層内になければなりません。 textFieldInputをサブビューとして追加する必要があります。

UIResponderにおけるAppleのドキュメントを1として:あなたは、このようなビューファーストレスポンダとしてResponderオブジェクトを作るために、このメソッドを呼び出すことができ

。ただし、そのビューがビュー階層の一部である場合にのみ、そのビューで呼び出す必要があります。ビューのwindowプロパティがUIWindowオブジェクトを保持している場合は、ビュー階層にインストールされています。 nilを返すと、ビューは階層から切り離されます。

+0

それはコードの私の最初のバージョン上の階層の一部ではありませんでした。ビュー階層のその部分。 ViewDidLoadに[controls becomeFirstResponder]を追加しました。だから私はコントロールを見ることができるので、私はビューの階層内にあると仮定します。それをviewDidLoadに追加すると、その時点ですでに追加されていることが確認されます。この変更により、まだ正しく動作していません。 – scooter133

+0

textFieldInputはどのように宣言されていますか?私はそれがあなたの呼び出しbecomeFirstResponderポイントで有効な値を持っているのだろうかと思います。 また、あなたはcreateElementInputControlの内部にbecomeFirstResponderコールを入れてみましたか? – Rayfleck

+0

私はいくつかの明確さのためにコードを変更しましたので、サポートコードを追加する必要はありませんでした。 'UITextField * textFieldInput = [[UITextField alloc] initWithFrame ...'のように宣言し、ビューに追加した後にtextFieldInputを解放してから、後でポインタに渡して後でアクセスできます。 becomeFirstResponderはもともとcreateElementInputControl内にありました。 – scooter133

0

あなたがdidBeginEditingから最初のレスポンダになると、無限ループに入ります。理由は、becomeFirstResponderを呼び出すとdidBeginEditingが呼び出されます。私はbecomeFirstResponderコードを削除するので、それは

をカーソルの点滅を説明し、あなたの声明、ポップオーバーはなし点滅挿入ポインタものの、 通常通り出てきます。私はフィールドをタップし、 挿入ポインタ、Xクリアコンテンツボタン、そしてはいキーボードを取得します。

あなたの問題を解決するために、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. 
} 
+0

これは私のコードには当てはまりません。 OPを編集してより多くのサポートコードを追加しました。 didBeginEditingでは、私はただresignFirstResponderを呼び出し、次に2番目のUITextFieldを管理するPopoverを呼び出します。 – scooter133

関連する問題