In my project I have several pages with many UITextField-s. So I figured it would be better to create an utility method named hideKeyboard which would work in any case.
Here is my solution, but actually something in this code doesn’t feel right.
Is there any better solutions for this?
+(void) hideKeyBoard {
UITextField* t = [[UITextField alloc] initWithFrame:CGRectNull];
[[UIApplication sharedApplication].keyWindow addSubview:t];
[t becomeFirstResponder];
[t resignFirstResponder];
[t removeFromSuperview];
}
A pretty simple solution is to use the responder chain as noted here
By sending the action to
nilit get sent into the responder chain and of course the first object that get’s a chance to respond is the object that is thefirstResponderSide note
The only reason I saw this post is because of the weekly newsletter iOSDevWeekly, which is definitely worth subscribing to
Edit
I guess brute force way of doing it would be