How to check when a UITextView is being edited?

I use the following code, but it is not recognized when I start editing a UITextView:

-(void)textViewDidBeginEditing:(UITextView *)textView{ [done setHidden:NO]; NSLog(@"Started editing target!"); } 

Why is this?

I added a delegate to the .h file.

+4
source share
5 answers

Try setting the delegate of your UITextView. You need to connect the output to the delegate in Interface Builder or if you create it programmatically, you can:

 yourTextView.delegate = self; 

to set the delegate to the controller that you insert into your element.

+5
source
 if ([self.textView isFirstResponder]) ... 

UPDATE: I include the full source to indicate that the UITextView is definitely responding to isFirstResponder @ d2burke

 #import "TextViewController.h" @interface TextViewController () @property (nonatomic, retain) IBOutlet UITextView *textView; @end @implementation TextViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (IBAction)click:(UIButton *)check { BOOL isActive = [self.textView isFirstResponder]; NSLog(@"%d", isActive); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 
+5
source

make sure that you:

  • nameOfTextView.delegate = self;
  • show the compiler that you are using UITextViewDelegate in your class
+2
source
  • Firstly you have to set UIViewController <UITextViewDelegate>
  • Set

    yourTextview.delegate = self;

  • And catch this delegate using

    -(void)textViewDidBeginEditing:(UITextView *)textView { [self.yourTextview setText:@""]; [yourTextview setTextColor:[UIColor blackColor]]; }

+1
source

There may also be a “duh” answer, but if you created your textView in IB, did you forget to plug in the socket?

0
source

Source: https://habr.com/ru/post/1381352/


All Articles