【问题标题】:Can't dismiss MFMailComposeViewController in Swift 3.0不能在 Swift 3.0 中关闭 MFMailComposeViewController
【发布时间】:2017-08-07 07:18:33
【问题描述】:

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

【问题讨论】:

标签: ios swift3 mfmailcomposeviewcontroller


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多