我已经在TableView中创建了设置页。当我点击行0时,将调用活动视图控制器。当我点击row2时,MailComposeController被调用。
调用了MailComposeController,但当我点击邮件屏幕上的“取消”或“发送”按钮时,它不起作用。
这是密码

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        if indexPath.row == 0 {

            let message = "Hey download my app [LINK]"
            let shareView = UIActivityViewController(activityItems: [message], applicationActivities: nil)
            self.present(shareView, animated: true, completion: nil)

        } else if indexPath.row == 1 {
            let mailCompose = MFMailComposeViewController()

            mailCompose.mailComposeDelegate = self

            mailCompose.setToRecipients(["[email protected]"])

            mailCompose.setSubject("feedback")

            mailCompose.setMessageBody("text", isHTML: false)

            if MFMailComposeViewController.canSendMail()

            {
                self.present(mailCompose, animated: true, completion: nil)
            }

            else{

                print("error...!")

            }
        }



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

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

        }

最佳答案

您必须将delegate方法放在ViewController中,而不是放在tableView:didSelectRowAt方法中:

extension ViewController: MFMailComposeViewControllerDelegate {
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }
}

10-08 15:34