按取消或发送按钮后,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)
}
答案 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