Search code examples
xcoderesignfirstresponder

Why won't text fields respond to hiding the keyboard?


This is my code:

- (BOOL) textFieldShouldReturn:(UITextField *)textField  {
    [txtSiteDesc resignFirstResponder];
    [txtDesc resignFirstResponder];
    [ssFS resignFirstResponder];

    return YES;

}

This is the .h file:

#import <UIKit/UIKit.h>

@interface slEnterDataViewController : UITableViewController <UITextFieldDelegate>  {

    UITextField *txtSiteDesc;
    UITextField *txtDesc;
    UITextField *ssFS;
}

@property (nonatomic, retain) IBOutlet UITextField *txtSiteDesc;
@property (nonatomic, retain) IBOutlet UITextField *txtDesc;
@property (nonatomic, retain) IBOutlet UITextField *ssFS;

@end

It works for the txtSiteDesc, but not any of the others. I assume the problem is in the textFieldShouldReturn method; I thought I could check the value of "textField" to see which field it is and then execute the appropriate "resignFirstResponder" and return. I'm close (I think) but not close enough.

Help would be greatly appreciated. :D


Solution

  • Is it possible that you've set the delegate for txtSiteDesc but not for your other two text fields? This would explain why textFieldShouldReturn: is called for your first text field not not the others. Make sure you are setting the delegate property of all three textfields to self (where self = your view controller).