-1
私はSwiftの本を使ってコードを学習しようとしています。ビューを閉じるためにデリゲートメソッドを追加しましたが、機能しません。私はここで何が欠けていますか?メールを閉じるためにアプリケーションを作成できませんビューコントローラを作成して最初の画面に戻る
あなただけIBAction
の外にデリゲート関数を宣言する必要が
@IBAction func emailButtonTapped(_ sender: UIButton) {
if !MFMailComposeViewController.canSendMail() {
print("Can not send mail")
return
}
guard MFMailComposeViewController.canSendMail() else { return }
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients(["[email protected]"])
mailComposer.setSubject("Look at this")
mailComposer.setMessageBody("Hello, this is an email from the app I made.", isHTML: false)
present(mailComposer, animated: true, completion: nil)
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
dismiss(animated: true, completion: nil)
}
}
'mailComposeController(_コントローラ:MFMailComposeViewController、didFinishWith結果:MFMailComposeResult、エラー:?エラー)が' IBAction内で宣言されていますそれはちょうどタイプミスですか?それは外にあるべきです。 – Samantha
ああ、それは働いた。私はまだこれを学んでいるので、まだ非常に新しいです。ありがとうございます:) – shayaa
@サマンサ答えとしてあなたのコメントを追加します。 –