OhDoh
OhDoh

Reputation: 433

UITextField bind

I can't figure out why that code is not working for me.

ViewController.h

...
@property (nonatomic, copy) UITextField *textField;
...

ViewController.m

-(void)viewDidLoad
{

    [self.textField addTarget:self 
                           action:@selector(textIsChanged:) 
                           forControlEvents:UIControlEventEditingChanged];

}

-(void)textIsChanged:(id)sender;
{
    NSLog(@"Changed");
}

When I type something in the textField textIsChanged method is never invoked.

Upvotes: 0

Views: 1135

Answers (1)

sch
sch

Reputation: 27506

You should declare textField as an IBOutlet like this:

@property (nonatomic, retain) IBOutlet UITextField *textField;

or, if you are using ARC (Automatic Reference Counting):

@property (nonatomic, strong) IBOutlet UITextField *textField;

and bind it from the xib file in interface builder.

Upvotes: 2

Related Questions