无法解除Swift 3.0中的MFMailComposeViewController

时间:2017-08-07 07:18:34

标签: ios swift3 mfmailcomposeviewcontroller

按取消或发送按钮后,MFMailComposeViewController无法解除。我在课堂上添加了MFMailComposeViewControllerDelegate,但仍然没有工作?

这是我的代码:

func sendEmail() {
    let MailVC = MFMailComposeViewController()
    MailVC.mailComposeDelegate = self
    MailVC.setToRecipients(["\(emailLabel?.text)"])
    MailVC.setSubject("Set your subject here!")
    MailVC.setMessageBody("Hello this is my message body!", isHTML: false)
    // Present the view controller modally.
    self.present(MailVC, animated: true, completion: nil)
}

func mailComposeController(controller: MFMailComposeViewController,
                           didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    // Dismiss the mail compose view controller.
    controller.dismiss(animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:4)

委托方法签名错误。您在_参数之前缺少controller。试试这个。

public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    // Dismiss the mail compose view controller.
    controller.dismiss(animated: true, completion: nil)
}

并确保这一点。

class ViewController: UIViewController ,MFMailComposeViewControllerDelegate