Keyboard not showing after MFMessageComposeViewController

In the iPhone app, I have a button UITextViewand a button that allows the user to send content UITextViewas a text message. The code is as follows:

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;

picker.body = textView.text;

[self presentModalViewController:picker animated:YES];

Everything works fine, except when the message has been sent or Canceled to MFMessageComposer: The keypad for is UITextViewno longer displayed, even if the cursor is blinking .

I tried several things, including [textView resignFirstRepsonder]buttons and buttons in the code -viewDidDisappear. [textView becomeFirstResponder]in the method MFMessageComposeViewControllerDelegateor -viewDidAppearnothing has changed ...

Any ideas?

+3
source share
7 answers

, fabian, , , [self dismissModalViewControllerAnimated:NO], [textView becomeFirstResponder], . - ; iOS 4.2.

+6

, , . MFMessageComposeViewControllerDelegate , :

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    [self dismissModalViewControllerAnimated:YES];
    [self becomeFirstResponder];
}

,

+1

, , startFirstResponder :

[textField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.01];
+1

UIAlert MFMessageComposeViewController, (0,5 )

+1

, :

- (void) actionSheet:(UIActionSheet *)actionSheet 
willDismissWithButtonIndex:(NSInteger)buttonIndex

- (void) actionSheet:(UIActionSheet *)actionSheet 
didDismissWithButtonIndex:(NSInteger)buttonIndex`

MFMessageComposeViewController.

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
             didFinishWithResult:(MessageComposeResult)result

I [textView becomeFirstResponder], . viewDidAppear:. UITextField.

, , ...

0

iOS 5, . MFMessageComposeViewController, UITextView:

[self presentViewController:messageComposer animated:YES completion:NULL];
[textView resignFirstResponder];

Then in the delegate method messageComposeViewController:didFinishWithResult:do the following:

[controller dismissViewControllerAnimated:YES completion:^{
  [textView performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];
}];

This fixed the keyboard extinction issue for me. Without the need to constantly close the keyboard.

0
source

This behavior will not be displayed if the viewController, which is displayed before the modal VC, is a child of the navigation controller. So the solution is to create a fake UINavigationController and add a VC controller to the navigation controller.

0
source

Source: https://habr.com/ru/post/1787138/


All Articles