gpt4 book ai didi

ios - 使两个不同的按钮创建两个不同的电子邮件主题

转载 作者:行者123 更新时间:2023-11-28 15:05:00 25 4
gpt4 key购买 nike

我正在尝试使用 if indexPath.section == 1 && indexPath.row == 0if indexPath.section == 1 && 显示两个不同的按钮indexPath.row == 1 当我打开电子邮件时有不同的主题。两个按钮都拉出同一个主题(建议: )。我如何让程序区分它们?

import UIKit
import Foundation
import MessageUI

class AccountViewController: UITableViewController, MFMailComposeViewControllerDelegate {

override func viewDidLoad() {
super.viewDidLoad()

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.view.backgroundColor = .clear

}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 1{
print("pressed")
let mailComposeViewController2 = configureMailController()
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController2, animated: true, completion: nil)
} else {
showMailError()
}
}
if indexPath.section == 1 && indexPath.row == 0 {
print("pressed")
let mailComposeViewController = configureMailController()
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
showMailError()
}
}
}
//if indexPath.section == 1 && indexPath.row == 1 {

//}
func configureMailController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["SolsticeOfficialLLC@gmail.com"])
mailComposerVC.setSubject("Suggestion: ")

return mailComposerVC
}
func configureMailController2() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["SolsticeOfficialLLC@gmail.com"])
mailComposerVC.setSubject("Report: ")

return mailComposerVC
}
func showMailError() {
let sendMailErrorAlert = UIAlertController(title: "Could not send email", message: "Your device could not send email", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "OK", style: .default, handler: nil)
sendMailErrorAlert.addAction(dismiss)
self.present(sendMailErrorAlert, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith: MFMailComposeResult, error: Error?){
controller.dismiss(animated: true, completion: nil)
}

}

最佳答案

您需要添加一个参数来帮助您:

func configureMailController(subject = "Unspecified Subject") -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["SolsticeOfficialLLC@gmail.com"])
mailComposerVC.setSubject(subject)

return mailComposerVC
}

然后,在配置的时候按你喜欢的方式做:

let mailComposeViewController1 = configureMailController("Specific Subject 1")

....

let mailComposeViewController2 = configureMailController("Specific Subject 2")

关于ios - 使两个不同的按钮创建两个不同的电子邮件主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48615352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com