MFMailComposeViewController not dismissing

前端 未结 5 840
名媛妹妹
名媛妹妹 2021-01-05 04:53

I have the following code that gets called in didSelectRowAtIndexPath. The issue is, when I click the cancel button, it prompts for save draft or discard. But when I click

相关标签:
5条回答
  • 2021-01-05 05:37

    There could be several problems:

    1. Not adding protocol implemantation in the .h

      @interface yourClass : UIViewController <MFMailComposeViewControllerDelegate>
      
    2. Not adding the relevant function in .m:

      -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:    (MFMailComposeResult)result error:(NSError*)error {
           [self dismissModalViewControllerAnimated:YES];
      }
      
    3. My error was not setting the correct delegate, but I fixed it :) and now it works for me:

       picker.mailComposeDelegate = self;
      
    0 讨论(0)
  • 2021-01-05 05:52

    Use:

    dismissViewControllerAnimated:completion:
    

    DEPRECATED FROM IOS 6.0:

    Add this method to your class:

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

    Have fun

    0 讨论(0)
  • 2021-01-05 05:53

    Swift Implementation:

    Make sure your MFMailComposeViewController protocol and delegate is being called every time its function being executed.

    This solves the issue of MFMailComposeViewController not being dismissed.

         let subj = "Test"
         let messageBody = "Test"
         let toRecipents = ["example@xyz.com"]
         let mc: MFMailComposeViewController = MFMailComposeViewController()
         mc.mailComposeDelegate = self
         mc.setSubject(subj)
         mc.setMessageBody(messageBody, isHTML: true)
         mc.setToRecipients(toRecipents)
         self.present(mc, animated: true, completion: nil)
    
    0 讨论(0)
  • 2021-01-05 05:55

    I've described the problem and the way it can be solved more detailed here: https://stackoverflow.com/a/13576408/691660

    I am not sure if Luda caught the core of the problem. No difference whether you specify the delegate or not, that does not work in case of modal+modal MFMailComposeViewController instance.

    0 讨论(0)
  • 2021-01-05 05:56

    "dismissModalViewControllerAnimated:"is deprecated in iOS 6.0

    iOS 7 use:

    "dismissViewControllerAnimated:completion:"

    0 讨论(0)
提交回复
热议问题