Search code examples
objective-ccocoa-touchipaduikeyboardresignfirstresponder

resignFirstResponder not hiding UIkeyboard in iPad


I have an iPad application in which resignFirstResponder does't seems to be working. I have tried many solutions. I am just calling resign first responder from the instance of the firstResponder object but keyboard is remain there on the screen. THen I tried by iterating all the window to get the instance of the first responder and then I am calling the resignFirstResponder from that instance.

I also try by creating the category of the UIViewController for the following methods.

  - (BOOL)disablesAutomaticKeyboardDismissal
    {
         return NO;
    }

But this solution is also not working for me. And this keyboard problem is there in all the textfield of application not only for some specific textfield.

Update: In different part of the app I am using different code for this purpose. Here is the code

- (void)textFieldDidEndEditing:(UITextField *)mtextField
 {
 [mtextField resignFirstResponder]; this one is not required but I have just write   it here.
 }

- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if([string hasSuffix:@"\n"])
{
    [theTextField resignFirstResponder];
    return NO;
}
return YES;
}

Update: When I try by running the application in the simulator, some times it resignFirstResponder is working, but not on every launch even in simulator.


Solution

  • I got the solution for this problem. Actually there seems to some change in the apple cocoa API. In my app I have an UIAlertView, which we used to display to show that some operation is going on and user should wait to finish it. For that purpose the code I use in my app was

    - (void)displayAlertView
       {
         UIAlertView *alertView = creating the object;
         UIActivityIndicatorView *activityIndicator= creating the object;
         [alertView addSubview:activityIndicator];
         [activityIndicator startAnimating];
         [alertView show];
         [alertView release];
        }
    
    -(void)didPresentAlertView:(UIAlertView *)alertView
     {
          [alertView dismissWithClickedButtonIndex:0 animated:NO];
     }
    

    The problem get resolved when I use the code below in my application

      -(void)didPresentAlertView:(UIAlertView *)alertView
     {
          [self performSelector:@selector(dismissView:) withObject:alertView afterDelay:0.0];
    
     }
    
      -(void)dismissView:(UIAlertView*)alertView
     {
          [alertView dismissWithClickedButtonIndex:0 animated:NO];
     }
    

    I think here some thing is going wrong in the UIAlertView, and because of that keyboard is not hiding when resigning as the first responder.