在Swift 3.0中无法关闭MFMailComposeViewController

5

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)
}

检查一次委托是否被正确调用,或者如何关闭MFMailComposeViewController。 - Anbu.Karthik
1个回答

5
委托方法签名错误。在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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接