IOS does not respond to the processing of the presentmodalviewcontroller Interface

Source: Internet
Author: User

Recently, IOS's email sharing and SMS text message sharing functions are simple functions. However, I found that the opened email interface and SMS interface never responded to the buttons on navigationcontroller, I felt very strange. Finally, I found that I needed to close the opened view in the delegate implementation method of these interfaces. It was a bit awkward! I am sending a piece of code, and you may understand it!

Note: To call the function of sending text messages and emails, you must introduce a library: messageui. framework.

You also need to import some classes:

#import <MessageUI/MessageUI.h>#import <MessageUI/MFMailComposeViewController.h>

The following code is the text message sent by IOs:

-(void)sendSMSComposerSheet{    MFMessageComposeViewController *messageCtrl = [[MFMessageComposeViewController alloc] init];    messageCtrl.messageComposeDelegate = self;    messageCtrl.body = @"share ....";    [self presentModalViewController:messageCtrl animated:YES];}

The delegation of this Code is mfmessagecomposeviewcontrollerdelegate.

However, my code also implements delegation. The Code is as follows:

 

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

However, it is okay to open the text message interface. The key is that the cancel button on the text message interface is not matched. Finally, I thought about it. It is estimated that the open view should be closed in the delegate implementation method, the result is true!
The above code is modified:

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

Or:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{    [controller dismissViewControllerAnimated:YES completion:^{}];}

Both methods are available, so that IOS can use presentmodalviewcontroller to open viewcontroller and corresponding buttons on viewcongroller!

At the same time, the Code for sending emails to iOS is appended:

-(Void) sendmailcomposersheet {mfmailcomposeviewcontroller * mailctrl = [[mfmailcomposeviewcontroller alloc] init]; mailctrl. mailcomposedelegate = self; [mailctrl setsubject: @ "mail title"]; [mailctrl setmessagebody: @ "Mail content" ishtml: No]; [self presentmodalviewcontroller: mailctrl animated: Yes];}

Related delegation: mfmailcomposeviewcontrollerdelegate

Interface Processing

-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{     [controller dismissModalViewControllerAnimated:YES];}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.