Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-(void)textFieldDidBeginEditing:(UITextField *)sender.. this function is not called when i select textfield?

I m using -(void)textFieldDidBeginEditing:(UITextField *)sender this function in my application. this is not called when i select the textfield. here's the code...

-(void)textFieldDidBeginEditing:(UITextField *)sender{  
    if([sender isEqual:txtName])//txtName is the IBOutlet of the UITextField  
    {  
        NSLog(@"Name");  
    }  
    else{  
        NSLog(@"NO_Name");  
    }  
}
like image 892
Chinju Avatar asked Nov 26 '10 12:11

Chinju


2 Answers

Make sure to complete 2 simple steps

1 - Implement the delegate UITextFieldDelegate

@interface yourViewController : UIViewController <UITextFieldDelegate>

2 - Set the delegate

yourTextField.delegate = self

If you have many text fields in your view, you can set delegate for all of your text fields like this

for (id subView in self.view.subviews)
    {
        if ([subView isKindOfClass:[UITextField class]]) {
            [subView setDelegate:self];
        }
    }
like image 34
Khawar Avatar answered Oct 08 '22 23:10

Khawar


Did you set delegate of UITextField's instance to current view controller like this:

textField.delegate = self; (self means the instance where callback textFieldDidBeginEditing is overridden)

like image 108
Sanniv Avatar answered Oct 08 '22 22:10

Sanniv