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.


Color Helper – Objective C

I got some Color Helper which was much useful for me to just simply set the RGB color code in the UI Fields in UIKit

here what i get …

#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 \alpha:(a)]

#define HSVCOLOR(h,s,v) [UIColor colorWithHue:(h) saturation:(s) value:(v) alpha:1]

#define HSVACOLOR(h,s,v,a) [UIColor colorWithHue:(h) saturation:(s) value:(v) alpha:(a)]

#define RGBA(r,g,b,a) (r)/255.0, (g)/255.0, (b)/255.0, (a)

Simply put the above four in ur .pch file or any other file (make sure you import  it to use this Helper Methods)

i grab this code from three20

Now using this you just need to set color as

view.setBackgroundColor = RGBCOLOR(40, 35, 56);

RGBACOLOR can be used to set color along with View’s alpha .. RGBACOLOR(40, 35, 56, 0.6) fourth parameter (0.6) will be for alpha in this case

Hope this help others a Lot !!