Dismiss keyboard in Modal View Controller at UIModalPresentationFormSheet mode

Did you tried to dismiss keyboard in a modal view controller at UIModalPresentationFormSheet mode ??

Well, I was quite amazed knowing that keyboard doesn’t dismiss even after writing resignFirstResponder to all input elements in a modal view controller at UIModalPresentationFormSheet mode.

Apple’s reason is ” they kept it that way to avoid the keyboard coming up and going down when switching between input elements in the modal form .

I need to dismiss it in UIModalPresentationFormSheet and can’t select other UIModalPresentationStyle ..(doing so is against the design architecture of app)

After searching my colleague got up a link related to this problem http://viraj-workstuff.blogspot.com/2010/12/resignfirstresponder-does-not-hide.html 

Solution mentioned in above was not what I really wanted as it just hide the keyboard by setting its view property setHidden:TRUE not like the one which normally hide keyboard when called resignFirstResponder  in animated way.

I found another link which nearly solves the problem http://stackoverflow.com/questions/5337126/ipad-dismiss-keyboard-for-modal-view-controller-in-uimodalpresentationformsheet 

this is what I wanted  🙂

This exactly work like normal Dismiss Keyboard type BUT as mentioned there App got rejected from AppStore coz used private API

We found that your app uses one or more non-public APIs, which is not in compliance with the App Store Review Guidelines. The use of non-public APIs is not permissible because it can lead to a poor user experience should these APIs change.

We found the following non-public APIs in your app:

activeInstance dismissKeyboard

So I followed the way mention as answer to that post of using NSSelectorFromString()

Below is my code by using NSSelectorFromString

@try {

Class UIKeyboardImpl = NSClassFromString(@”UIKeyboardImpl”);
id activeInstance = [UIKeyboardImpl performSelector:NSSelectorFromString(@”activeInstance”)];
[activeInstance performSelector:NSSelectorFromString(@”dismissKeyboard”)];

@catch (NSException *exception) {
//NSLog(@”%@”, exception);

Still I dont know whether this would by 100% accepted by AppStore. I tried a way which work for me and suggest by the post to avoid rejection from AppStore!! 🙂 [Update:] It worked fine without rejection.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s