Reputation:
I use
[self.assuntoTextField addTarget:self action:@selector(testarSeTemTexto) forControlEvents:UIControlEventEditingChanged];
to get the text value of the UITextFields
, but I can't do the same with UITextViews
, how can I do that WHILE user is still editing the TextView?
Upvotes: 0
Views: 1100
Reputation: 3607
Make your viewController a delegate of textView like this:
@interface ViewController : UIViewController<UITextViewDelegate>
This is your delegate method:
- (void)textViewDidChange:(UITextView *)textView
See this for more info
Upvotes: 1
Reputation: 18865
If you don't need validation and simply want to be informed that the text had been changed simply assign a delegate to this UITextField
(if yiu haven't done this yet) and implement a method
- (void)textViewDidChange:(UITextView *)textView
{
NSString *text = textView.text;
}
If you want to implement some kind of validation then the proper method to use would be
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSString *finalTextWillBe = [textField.text stringByReplacingCharactersInRange:range
withString:string];
//validation comes here...
if (final text passes your validation)
{
return YES;
}
else
{
return NO;
}
}
NOTE: if you are using more than one text field you will have to identify the source somehow. Either by setting its tag
or by holding a reference (ivar, property...) to the text fields.
Upvotes: 5