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

3)您可能希望在比赛上做一些时髦的正则表达式工作,currentTextInField isEqualToString:尽管这是一个单独的问题

于 2012-10-12T16:05:32.933 回答