Hiding keyboard in iPad with UITextView , can do this in iphone not iPad.

Posted by user271753 on Stack Overflow See other posts from Stack Overflow or by user271753
Published on 2010-03-23T07:06:19Z Indexed on 2010/03/23 7:13 UTC
Read the original article Hit count: 471

Hey the code below when written in HelloWorldAppDelegate.m in an iPhone app having UITextView hides the keyboard when the app starts :

The UITextView is editable thats what I want in iPad Also

But how can do the same in iPad its not working at all ! ! ! ! ! ! !

And also I have checked that I can use Subviews if I want to keep this to my app itself

    - (void)applicationDidFinishLaunching:(UIApplication *)application {    


 //For hiding the Keyboard
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

///
/// Hiding the Keyboard
///
- (void)keyboardWillShow:(NSNotification *)note {

     //The UIWindow that contains the keyboard view
     UIWindow* tempWindow;

     //Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. 
     //UIKeyboard is a subclass of UIView anyways
     UIView* keyboard;

     //Check each window in our application
     for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
    {
      //Get a reference of the current window
      tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];

      //Get a reference of the current view 
      for(int i = 0; i < [tempWindow.subviews count]; i++)
        {
          keyboard = [tempWindow.subviews objectAtIndex:i];

          if (!strcmp(object_getClassName(keyboard), "UIKeyboard"))
            {
              NSLog(@"hide keyboard");
              [keyboard setHidden:YES];
              return;
            }
        }
    }
}

Regards

© Stack Overflow or respective owner

Related posts about ipad

Related posts about iphone