In my iphone app. in MFMailComposerView
view when i am clicking to recepients then key board appears . After i am clicking return key in the key board. but key board not disappear.
Asked
Active
Viewed 323 times
1

Goutham
- 299
- 1
- 24
-
NO, the keyboard can never be dismissed – P.J Jan 04 '13 at 09:22
-
With some recursive responder chain hacking, this might work pre-iOS 6, but now that Mail Controllers are remote, I absolutely cannot recommend you try to resign it's first responder remotely. – CodaFi Jan 04 '13 at 09:24
-
i think return key moves from one textfield to another textfield in MFMailComposerView.When last textfield it returns. – Paresh Navadiya Jan 04 '13 at 09:29
-
**Do NOT use the Xcode tag for questions unrelated to Xcode!** – Jan 04 '13 at 09:42
2 Answers
3
Use UIWindow
notifications keyboard and just use bellow code for display the MFMailComposerViewController
..
- (IBAction)showMailController {
//Present mail controller on press of a button, set up notification of keyboard showing and hiding
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
//... and so on
}
- (void)keyboardWillShow:(NSNotification *)note {
//Get view that's controlling the keyboard
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];
//set up dimensions of dismiss keyboard button and animate it into view, parameters are based on landscape orientation, the keyboard's dimensions and this button's specific dimensions
CGRect t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
button.frame = CGRectMake(324,(290-t.size.height),156,37);
button.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[[[[[firstResponder superview] superview] superview] superview] addSubview:button];
button.alpha = 1.0;
button.frame = CGRectMake(324,(253-t.size.height),156,37);
[UIView commitAnimations];
}
- (IBAction)dismissKeyboardInMailView {
//this is what gets called when the dismiss keyboard button is pressed
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];
[firstResponder resignFirstResponder];
}
- (void)keyboardWillHide:(NSNotification *)note {
//hide button here
[button removeFromSuperview];
}
i got some of this code from this link..
programmatically-align-a-toolbar-on-top-of-the-iphone-keyboard

Community
- 1
- 1

Paras Joshi
- 20,427
- 11
- 57
- 70
-
1@NitinGohel: what about the above dismissing code ? It is exact the same code used in http://stackoverflow.com/questions/4872565/mfmailcomposeviewcontroller-keyboard-issue – Midhun MP Jan 04 '13 at 09:41
0
You can use the following code for this.
UIWindow *mainWin = [[UIApplication sharedApplication] keyWindow];
UIView *responder = [mainWin performSelector:@selector(firstResponder)];
[responder resignFirstResponder];
But if you use this in your app, Apple will surely reject your app because UIWindow's firstResponder method is a private API.
Reference : SO
-
2Please put atlist link of copy answer this answer from :- http://stackoverflow.com/questions/4872565/mfmailcomposeviewcontroller-keyboard-issue – Nitin Gohel Jan 04 '13 at 09:34