I want to use addTarget:action on UITextView like on (UITextField or UIButton).
I want to call a method on UITextView.
please give some possible solution...
Thank You...
UITextView *TXT_First_Tag = [[UITextView alloc] initWithFrame:CGRectMake(5, textPosY, 350, 65)];
TXT_First_Tag.backgroundColor = [UIColor whiteColor];
TXT_First_Tag.font = [UIFont fontWithName:@"Arial-BoldMT" size:30.0];
TXT_First_Tag.editable =YES;
TXT_First_Tag.tag = i;
TXT_First_Tag.textColor = [UIColor blackColor];
[TXT_First_Tag addTarget:self action:@selector(C6Loop) forControlEvents:UIControlEventEditingDidEnd]; // This Line I want to use, it's working fine on textfield...
[scrollview addSubview:TXT_First_Tag];
We use UITextView delegate methods for this purpose.
Put this in your code.
UITextView *TXT_First_Tag = [[UITextView alloc] initWithFrame:CGRectMake(5, textPosY, 350, 65)];
TXT_First_Tag.backgroundColor = [UIColor whiteColor];
TXT_First_Tag.font = [UIFont fontWithName:@"Arial-BoldMT" size:30.0];
TXT_First_Tag.editable =YES;
TXT_First_Tag.delegate = self;
TXT_First_Tag.tag = i;
TXT_First_Tag.textColor = [UIColor blackColor];
[scrollview addSubview:TXT_First_Tag];
- (void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(@"Begin editing");
}
- (void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@"DidEndEditing");
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
NSLog(@"ShouldBeginEditing");
return TRUE;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
NSLog(@"ShouldEndEditing");
return TRUE;
}
If your controller implements the UITextViewDelegate
protocol, you can then set the controller as the text view's delegate in the controller's instance method, viewDidLoad()
:
yourTextView.delegate = self;
Then, if you want to perform a task before editing your text view, use:
-(void)textViewDidBeginEditing:(UITextView *)textView {}
And, if you want to do a task after editing your text view, use:
-(void)textViewDidEndEditing:(UITextView *)textView {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With