2

I've got this code working well for months (on iOS 5.1), but I didn't check it for a long time and now (probably iOS 6.0 issue) I've noticed that my MFMailComposeViewController doesn't show the keyboard even when focusing textfields like message body or recipients.

The strange thing is that it reacts on taps, so i can set cursor on 'To' or 'Subject' and the cursor appears, or I'm able to hold the tap to make the zooming glass pop up. But no keyboard :(

SCREENSHOT OF THIS

Here's the code I'm using:

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;        
[self presentModalViewController:mailer animated:YES];

I've been searching a lot about this and found something that deals with
[self resignFirstResponder] or [mailer becomeFirstResponder], but it didn't work.

If I add this code before or after presenting controller

NSLog(@"mailer become %d", [mailer canBecomeFirstResponder]);

It shows 0, however, the

NSLog(@"self resign %d", [self resignFirstResponder]);

shows 1, but it was 0 too before i added the

- (BOOL)canResignFirstResponder {
    return YES;
}

Docs say it should return YES by default, so it's double strange.

If I create an empty project with such code it works well, but I can't really do this because my current project is quite huge. Any help would be appreciated, getting stuck here...

Tested both on iPhone and iOS Simulator (both deployment target 5.1 and 6.0)

dreamzor
  • 5,795
  • 4
  • 41
  • 61
  • First of all, if you do everything right you don't mess with responders. I mean that instead of making it worse with `canBecomeFirstResponder`, `canResignFirstResponder`, `becomeFirstResponder` and `resignFirstResponder` you need to find what's done wrong and fix it. For example, you might want to stop using the deprecated code and replace it with `presentViewController:animated:completion:`. – A-Live Dec 13 '12 at 15:07
  • @A-Live thanks for the tip, didn't know it's deprecated. Changed it like you said and still can't get it to work :( – dreamzor Dec 13 '12 at 15:12
  • I can only suggest then to check if that is "presented" from the main thread (with `[[NSThread currentThread] isMainThread]`). – A-Live Dec 13 '12 at 15:40
  • @A-Live yes, it's running from the main thread. – dreamzor Dec 13 '12 at 15:46
  • There's no title for composer at screenshot, did you modify `MFMailComposeViewController` in any way ? – A-Live Dec 13 '12 at 16:17
  • @A-Live it doesn't need to have a title, with empty project it's working with keyboard and doesn't have any title... – dreamzor Dec 13 '12 at 16:22

3 Answers3

2

Just LOL. The problem was with the

[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar + 1]

somewhere in my app. Seems like they changed keyboard windowLevel in iOS 6, so that now it's behind. I'm quite lazy to do so, but it would be interesting to know exact windowLevel of the keyboard window :)
Be careful with that!

Thanks to everyone for helping anyway!

dreamzor
  • 5,795
  • 4
  • 41
  • 61
1

If you want to show the keyboard, you must take the text box from the mailer and then send the message becomeFirstResponder.

However, there is not straight forward way to do that. When you touch the box of the message, does the keyboard appear?

ipinak
  • 5,739
  • 3
  • 23
  • 41
  • no, it doesn't appear at all, even after touch, that's the problem :( but it reacts on touches with a blue text cursor and stuff... going to post a screenshot. – dreamzor Dec 13 '12 at 14:52
0

For others who may have come up with this keyboard issue in the MailComposer this solution worked for me:

  • Present the view then call "becomefirstResponder" on the same MFMailComposeViewController in the completion method.

    MFMailComposeViewController* mailCon = [[MFMailComposeViewController alloc] init]; [self presentViewController:mailCon animated:NO completion:^{ [mailCon becomeFirstResponder]; }];

Tope
  • 938
  • 2
  • 11
  • 15