0

UITextField に入力した後に何かを作成する UITextField のメソッドを探しています。

ボタンを使用して計算を行うメソッドがありますが、使用したくありません。UITextField に数値を入力した後で、このメソッドを実行してもらいたいです。

どの方法を使用するかについてのヒントはありますか?

助けてくれてありがとう。

4

4 に答える 4

3
  1. UITextFieldFieldDelegateプロトコルを実装する
  2. テキストフィールドのデリゲートをView Controllerに設定します

self.textField.delegate = self;

shouldChangeCharactersInRange次に、メソッドを実装します

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
        [self doCalculations];
        return NO;
    }
于 2013-11-04T02:50:31.690 に答える
1

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string入力したテキストをすぐに取得するために使用できます。または- (BOOL)textFieldShouldReturn:(UITextField *)textField、ユーザーがリターンを押したときにキャプチャし、その時点でテキスト フィールドからテキストを読み取るために使用できます。これらのメソッドはどちらも UITextFieldDelegate プロトコルにあり、そのドキュメントはこちらにあります

編集:

または、textChanged メソッドを使用[textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];して実装し、EditingChanged イベントをキャプチャすることもできます。

于 2013-11-04T02:47:44.463 に答える
0

はい、このコードを使用して行うことができます:-

このコードは、指定されたテキストを変更する必要があるかどうかをデリゲートに尋ねます。

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        [self yourMethodName];  //The method which you want to call.
        return YES;
    }

UITextFieldFieldデリゲートを呼び出します。これをよりよく理解するために、これを参照できます:-

https://developer.apple.com/library/ios/documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html#//apple_ref/occ/intfm/UITextFieldDelegate/textField:shouldChangeCharactersInRange:replacementString :

これがあなたを助けることを願っています。

于 2013-11-04T05:58:56.643 に答える
0
//in your ViewContoller.h
//Implement UITextFieldFieldDelegate protocol


//In your ViewContoller.m
//where you are creating your textfield.
textField.delegate = self;

// There are 2 delegate method that you can implement
// this method will be called whwn ever you enter a a letter.
// say you enter 'abcd' then this method will be called 4 times.  
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//do your calculation if required
    return YES;
}

//this method will be called when the textField will end editing, i.e when the keyboard resigns of the control goes to some other textField/textView
- (void)textFieldDidEndEditing:(UITextField *)textField {

}

要件に基づいて、1 番目または 2 番目の方法で計算を行うことができます。

于 2013-11-04T05:22:06.533 に答える