开发者

-(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:t开发者_C百科xtName])//txtName is the IBOutlet of the UITextField  
    {  
        NSLog(@"Name");  
    }  
    else{  
        NSLog(@"NO_Name");  
    }  
}


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)


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];
        }
    }


You must include UITextFieldDelegate in .h file

@interface yourViewController : UIViewController <UITextFieldDelegate>


You must include UITextFieldDelegate in your .h file, and also add YourTextField.delegate = self

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜