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

Discussion in 'iOS Programming' started by int3rc3pt0r, Mar 23, 2010.

  1. int3rc3pt0r macrumors newbie

    Joined:
    Feb 9, 2010
    #1
    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

    Code:
    Code:
        - (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
     
  2. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #2
    Discussion of iPad development is currently still under NDA.
     
  3. kimvillage macrumors newbie

    Joined:
    Oct 31, 2010
    #3
    Never perform the last if

    I wanna use your code when I click in a textview in Iphone developement.
    I want that textview remains editable but I want to hide the UIKeyboard because I created an alternative one which must appear.

    Your code never perform the last condition, that should hide the UIkeyboard.

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

    What's the problem?

    Thanx in advance.
    QUIM
     

Share This Page