2

In my app, I need to show history of text messages. I can show MFMessageComposeViewController, but keyboard appears there, which is something I do not need now. User can hide it by gesture, but I would like to hide it programmatically.

I cannot find a way ho to do this, but I am certain it is possible, as I saw it in another app (its named 'Mobilné platby').

Thank you in advance!

Reconquistador
  • 885
  • 8
  • 28
  • Try `[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];` or `[yourMessageComposeViewController.view setEndEditing:TRUE];` ? – Larme May 18 '16 at 12:16
  • sendAction is not doing anything. By second possibility, you probably meant [yourMessageComposeViewController.view endEditing:TRUE]; - it is retirning true, but keyboard is still there. – Reconquistador May 18 '16 at 12:35

2 Answers2

0

In viewDidload of MFMessageComposeViewController add at last,

 [self.view endEditing:YES];

If it's not work then try it in viewDidAppear

Update :

As Apple documentation states,

You must not modify the view hierarchy presented by this view controller. You can, however, customize the appearance of the interface using the UIAppearance protocol.

Refer apple documentation. And you can refer this answer also.

So, I think, It is not allowed to change in view hierarchy of MFMessageComposeViewController. You can just change appearance

hope this will help :)

Community
  • 1
  • 1
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • As that is system class, I have made subclass and tried this both in viewDidLoad and viewDidAppear. Both returns TRUE, but sadly without effect. – Reconquistador May 18 '16 at 12:46
  • If you are presenting this view controller the try this in completion handler of it – Ketan Parmar May 18 '16 at 13:10
  • I hav tried completion handler this way: [self presentViewController:comp animated:YES completion:^{ Boolean test = [comp.view endEditing:YES]; NSLog(@"4: %i", test); }]; It logs "4: 1", but keyboard is still there. – Reconquistador May 19 '16 at 06:02
  • I saw that in Apple documentation and I am not doing anything that breaks this. View hierarchy is fine for me, I just want to keyboard be closed (yes, user will be able to shot it with gesture - but that is not a problem for me). I even do not need to send SMS, or change its text. Just to show messages already sent and received. – Reconquistador May 19 '16 at 07:32
0

if just calling endEditing is not working. you can try this trick: When you are tapping button to open mail Composer write this line directly under it:

[self performSelector:@selector(function) withObject:nil afterDelay:2];

and your function will be:

- (void)function
 {
  [self.view endEditing:YES];
 }
Nitin
  • 451
  • 5
  • 17
  • Tried this both where I open composer (its in didSelectRowAtIndexPath, but it should not matter whether this or in button tapping) and in subclass of MFMessageComposeViewController viewDidAppear. While in both cases endEditing returns true, keyboard is still there. – Reconquistador May 19 '16 at 06:12