UITextField resignFirstResponder not working

I’m creating a UITextField programmatically in cocos2d-x and it shows up and works fine. When I click on it the keyboard comes up and I can type into the box. However, I can’t get the keyboard to close. The resignFirstResponder is getting called on the correct text field, I checked it with a breakpoint, but still wont go away. It seems nothing I do can make the keyboard go away. Can anyone please help me?

UIApplication* clientApp = [UIApplication sharedApplication];

UITextField *search = [[[UITextField alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 30.0)] autorelease];

search.borderStyle = UITextBorderStyleRoundedRect;
search.textColor = [UIColor blackColor];
search.font = [UIFont systemFontOfSize:18.0];
search.placeholder = @"Search";
search.backgroundColor = [UIColor whiteColor];
search.autocorrectionType = UITextAutocorrectionTypeNo;
search.keyboardType = UIKeyboardTypeNamePhonePad;
search.returnKeyType = UIReturnKeyDone;
search.clearButtonMode = UITextFieldViewModeNever;
search.delegate = (AppController *)clientApp.delegate;

[((AppController *)clientApp.delegate).getViewController.view addSubview:search];

In AppController.mm:

- (RootViewController*)getViewController
{
    return viewController;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

This fixed it, but is this a bad way of doing it? Thanks.

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

    cocos2d::CCEGLView * pGlView = cocos2d::CCDirector::sharedDirector()->getOpenGLView();
    if (pGlView)
        pGlView->setIMEKeyboardState(false);

    return YES;
}