views:

111

answers:

1

Hey guys,

I've been searching the web for a really long time, and I can't get this to work. On my text field I have, when I click on it and then press done or return it won't go away. I've done all the steps for every single tutorial but I still can't get it to work. I'm on firmware 3.1.2, but anyway here is the code in my ViewController.m:

- (void)viewDidLoad {

    [super viewDidLoad];

    blah.delegate = self;
    blah.returnKeyType = UIReturnKeyDone;

}

- (BOOL)blahShouldReturn:(UITextField *)blah{

    [blah resignFirstResponder];
    return YES;
}

viewcontroller.h:

@interface BlahViewController : UIViewController <UITextFieldDelegate> {
    IBOutlet UITextField *blah;

}

These are just cut outs from the files. Anyway can anyone help me? I can't get rid of the keyboard when I click on it...

Thanks,

Kevin

+4  A: 

I'm confused. Are you actually expecting a method called blahShouldReturn: to get called when you press the Return button? If you want to use the textFieldShouldReturn: delegate method, it has to be called textFieldShouldReturn:. You can use the UITextField parameter supplied with that method to determine which text field is sending the message. For example:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == blah) {
        [textField resignFirstResponder];
    } else if (textField == someOtherTextField) {
        // Do something else
    }
    return YES;
}
Alex