0

Objective cが初めてなので、例をいただければ幸いです。私がやろうとしているのは、テキストを UITextfield に入力し、IBAction の UITextView 内のテキストの出現を削除することです。

html、javascript、css のすべてを知っています。古い犬に新しいトリックを教えるのは難しいですが、それに取り組んでいます。
すべての返信に事前に感謝します。

-(IBAction)tel2{


[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:tel2 cache:YES];
[UIButton setAnimationDelegate:self];
[UIButton setAnimationDidStopSelector:@selector(test)];
[UIButton setAnimationDuration:.5];

if(tails2.tag==11){
    [tel2 addSubview:tails2];
    tails2.tag=22;



    textField.text = [NSMutableString stringWithFormat:@" %@", textField2.text];
}
else{
    [tel2 addSubview:heads2];
    tails2.tag=11;


    textField.text = [NSMutableString stringWithFormat:@"%@ %@", textField.text, textField2.text];

    }

[UIView commitAnimations];

}

4

3 に答える 3

1

あなたがやろうとしていることの多くを見ることなく、NSStriingでreplaceOccuranceOfStringメソッドを使用することができると思います(調べることはできますが、それはのようなものNSString *newString = [oldString replaceOccuranceOfString:"what you want to replace" withString""];です。削除したい特定の単語または単語のリストがあります。

于 2012-10-12T15:54:32.107 に答える
1

これはあなたがそれを行うことができる方法です

NSString* searchWord = @"word";

NSString* editedText = [textView.text stringByReplacingOccurrencesOfString:searchWord withString:@""];

textView.text = editedText;
于 2012-10-12T15:56:50.137 に答える
0

0) ビュー コントローラーで:

UITextField *fooTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, textFieldWidth, textFieldHeight)];
[self.view addSubview:fooTextField];
[self.view bringSubviewToFront:fooTextField];
fooTextField.delegate = self; //you need to add a couple of delegate methods here also

1) 次に以下を追加します。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@"UITextFieldTextDidChangeNotification" object:fooTextField];

ビューコントローラーのviewDidLoad;メソッドに

2) ビュー コントローラー クラスに次のメソッドを追加します。

   - (void)textFieldDidChange:(NSNotification *)notification {
        NSString *currentTextInTextField = [NSString stringWithString:[(UITextField*)notification.object text]];
        if ([currentTextInTextField isEqualToString:@"thisIsTheStringYouAreLookingFor"]) {
            [(UITextField*)notification.object setText:@"whateverYouWantToReplaceItWith"];
        }
    }

currentTextInField isEqualToString:3)それは別の質問ですが、マッチでファンキーな正規表現作業をしたいかもしれません

于 2012-10-12T16:05:32.933 に答える