Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which addTarget actions can we take on UITextView?

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];
like image 552
Samina Shaikh Avatar asked Apr 11 '12 09:04

Samina Shaikh


2 Answers

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;
}
like image 116
mChopsey Avatar answered Nov 03 '22 12:11

mChopsey


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 {}
like image 25
freelancer Avatar answered Nov 03 '22 13:11

freelancer