Dismiss keyboard in Modal View Controller at UIModalPresentationFormSheet mode

Did u 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 .

But i need to dismiss it in UIModalPresentationFormSheet and cant 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 

but solution mentioned in above was not what i really wanted .. coz 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.

Then further i got the link 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()

so here is the code which i rewritten 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 Cheat AppStore !! 🙂

Advertisements