1

I've got a UIViewController with an additional small UIView I created on top of it (subview). When I click a button this view hovers to the center of the screen. The issue is the i've got a UITextField in the additional UIView and i cannot seem to get the return key to work.

Although I set my IBAction to the event "Editing did end" of the text field, when i click the return key, the IBAction doesn't run.

What am I doing wrong?

4

5 に答える 5

0

インターフェイスでUITextFieldDelegateを確認してください

于 2012-11-06T08:39:54.040 に答える
0

たとえば、デリゲートを設定するだけです。yourtextfile.delegate=self;また、デリゲートメソッドを.hファイルに追加することも忘れないでください。

@interface contacts_detailView : UIViewController<UITextFieldDelegate>

そして、あなたは委任しますtextFieldDidEndEditing

- (void)textFieldDidEndEditing:(UITextField *)textField
{
//your new view apear code here 
    [textField resignFirstResponder];
}
于 2012-11-06T08:41:04.310 に答える
0

キーボード リターン用のコードをさらに記述する必要はありません。これを .m ファイルに書き込んでください。任意の数のテキスト フィールドに対して機能します。別のテキスト フィールドに対して再度書き込む必要はありません。

<UItextfieldDelegate> .h ファイルで使用します。次に、nib ファイルの fileowner と関連付けます。

- (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
     [self.view endEditing:YES];
     return YES;
     }
于 2012-11-06T09:12:15.740 に答える
0

「戻る」をクリックしても、「編集が終了しました」イベントはトリガーされません。UITextField で rejectFirstResponder を呼び出した場合にのみ、イベントがトリガーされます。

あなたがすべきことは、あなたの UIViewController を UITextField のデリゲートとして設定し、メソッドを実装することです

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
于 2012-11-06T08:41:53.940 に答える
0

まず、次のように TextField をファイルの所有者に委任します。

yourtextField.delegate = selfあなたのビューでDidLoad。

そして、これをView Controllerに追加します

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

それはうまくいくはずです。

于 2012-11-06T08:46:31.320 に答える