MFMailComposeViewController 不显示取消按钮
MFMailComposeViewController not showing Cancel button
我尝试了所有 SOF 解决方案,但对我的情况都不起作用。
我的应用正在使用标签栏,其中一个标签栏正在设置(表格视图)。用户可以点击支持单元格来发送电子邮件。
我可以调出电子邮件视图,但它没有取消按钮。关闭它的唯一方法是发送电子邮件或向下滑动 save/delete 草稿。
谢谢!!
import UIKit
import MessageUI
class SettingVC: UIViewController, UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate {
@IBOutlet weak var tableView: UITableView!
let mail = MFMailComposeViewController()
var fromSetting: Bool = false
let settingsSction = ["Section0", "Section1", "Section2"]
let settingsCell = [["Cell0"],
["Cell1"],
["Cell2", "Support"]]
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.navigationBar.barStyle = .black
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLoad() {
super.viewDidLoad()
setUpNavBar()
tableView.delegate = self
tableView.dataSource = self
mail.mailComposeDelegate = self
}
func setUpNavBar() {
self.navigationItem.titleView?.tintColor = .white
let settingsTitleLabel = UILabel()
settingsTitleLabel.textColor = .white
settingsTitleLabel.font = UIFont.boldSystemFont(ofSize: 18)
settingsTitleLabel.text = "Settings"
self.navigationItem.titleView = settingsTitleLabel
}
//MARK: Table View Sections
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
func numberOfSections(in tableView: UITableView) -> Int {
return settingsSction.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return settingsSction[section]
}
//MARK: Table View Cell Title
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return settingsCell[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "\(settingsCell[indexPath.section][indexPath.row])"
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 2:
switch indexPath.row {
case 1:
sendEmail()
default:
break
}
default:
break
}
}
func sendEmail() {
if MFMailComposeViewController.canSendMail() {
mail.navigationBar.tintColor = UIColor.orange
mail.setToRecipients(["support@example.com"])
mail.setSubject("I have an issue.")
self.present(mail, animated: true, completion: nil)
} else {
alertOK(title: "No Mail App Available", message: "Please install Mail app in your phone or use other mail app to send us the issue. Thank you.", sender: self)
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
}
问题已解决。我在 app delegate 中设置了导航栏颜色,所以它也使文本变成了白色。
我尝试了所有 SOF 解决方案,但对我的情况都不起作用。
我的应用正在使用标签栏,其中一个标签栏正在设置(表格视图)。用户可以点击支持单元格来发送电子邮件。
我可以调出电子邮件视图,但它没有取消按钮。关闭它的唯一方法是发送电子邮件或向下滑动 save/delete 草稿。
谢谢!!
import UIKit
import MessageUI
class SettingVC: UIViewController, UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate {
@IBOutlet weak var tableView: UITableView!
let mail = MFMailComposeViewController()
var fromSetting: Bool = false
let settingsSction = ["Section0", "Section1", "Section2"]
let settingsCell = [["Cell0"],
["Cell1"],
["Cell2", "Support"]]
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.navigationBar.barStyle = .black
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLoad() {
super.viewDidLoad()
setUpNavBar()
tableView.delegate = self
tableView.dataSource = self
mail.mailComposeDelegate = self
}
func setUpNavBar() {
self.navigationItem.titleView?.tintColor = .white
let settingsTitleLabel = UILabel()
settingsTitleLabel.textColor = .white
settingsTitleLabel.font = UIFont.boldSystemFont(ofSize: 18)
settingsTitleLabel.text = "Settings"
self.navigationItem.titleView = settingsTitleLabel
}
//MARK: Table View Sections
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
func numberOfSections(in tableView: UITableView) -> Int {
return settingsSction.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return settingsSction[section]
}
//MARK: Table View Cell Title
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return settingsCell[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "\(settingsCell[indexPath.section][indexPath.row])"
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 2:
switch indexPath.row {
case 1:
sendEmail()
default:
break
}
default:
break
}
}
func sendEmail() {
if MFMailComposeViewController.canSendMail() {
mail.navigationBar.tintColor = UIColor.orange
mail.setToRecipients(["support@example.com"])
mail.setSubject("I have an issue.")
self.present(mail, animated: true, completion: nil)
} else {
alertOK(title: "No Mail App Available", message: "Please install Mail app in your phone or use other mail app to send us the issue. Thank you.", sender: self)
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
}
问题已解决。我在 app delegate 中设置了导航栏颜色,所以它也使文本变成了白色。