Swift在MFMailComposeViewController中显示警告didFinishWith结果

时间:2017-02-04 11:51:28

标签: ios swift uitableview alert

我想在用户取消电子邮件时发出提醒。为此,我使用以下代码:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {

    if result == .cancelled {

        let alertController = UIAlertController(title: "E-Mail not sent!", message: "E-Mail not sent.", preferredStyle: .alert)

        alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction!) in
        }))

        present(alertController, animated: true, completion: nil)
    }

    controller.dismiss(animated: true, completion: nil)
}

调用该函数并解除Mail View,但不显示警报。我在UITableViewController中使用此代码。请有人帮帮我吗?

1 个答案:

答案 0 :(得分:1)

在completionBlock中显示alertController。

controller.dismiss(animated: true, completion: {
if result == .cancelled {
        let alertController = UIAlertController(title: "E-Mail not sent!", message: "E-Mail not sent.", preferredStyle: .alert)

        alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction!) in
        }))

        present(alertController, animated: true, completion: nil)
    }
})
像这样......