Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

int3rc3pt0r

macrumors newbie
Original poster
Feb 9, 2010
9
0
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
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.