我已經嘗試了幾種使用UIAlertController而不是UIAlertView的方式,但我無法使警報消失。預先感謝您提出任何進一步的建議。我是一個新手。UIAlertView'已被棄用在iOS 9.0
UIAlertView'在iOS 9.0中已棄用:UIAlertView已棄用。使用UIAlertController與UIAlertControllerStyleAlert的preferredStyle代替
這裏是我的代碼:
import MessageUI
class SecondViewController: UIViewController,MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func sendmail(sender: UIButton) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["[email protected]"])
mailComposerVC.setSubject("App Feedback")
mailComposerVC.setMessageBody("Feature request or bug report?", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
什麼不行?我看到你的'UIAlertView'代碼,但不是你在'UIAlertController'上的嘗試。有很多教程。 [Here](http://nshipster.com/uialertcontroller/)就是一個例子。 –
嘗試使用'UIAlertController'來更新您的問題。解釋你有什麼問題。並做一些搜索。有無數如何使用'UIAlertController'的例子。 – rmaddy