Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check when a UITextView is being edited?

I'm using the following code but it is not being recognised when I start editing the UITextView:

-(void)textViewDidBeginEditing:(UITextView *)textView{

[done setHidden:NO];

NSLog(@"Started editing target!");

}

Why is this?

I have added the delegate to the .h file too.

like image 617
pixelbitlabs Avatar asked Dec 06 '22 18:12

pixelbitlabs


2 Answers

Try to set the delegate of your UITextView. You need to connect the outlet to the delegate in Interface Builder or if you are creating it programmatically you can:

yourTextView.delegate = self;

to set the delegate to the controller you are inserting your element.

like image 137
Matteo Alessani Avatar answered Dec 25 '22 23:12

Matteo Alessani


if ([self.textView isFirstResponder]) ...

UPDATE: I include the full source to indicate UITextView definitely responds 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
like image 44
ohho Avatar answered Dec 26 '22 00:12

ohho