2015-10-15 4 views
-4

Я пробовал несколько способов использовать UIAlertController, а не UIAlertView, но я не могу сделать предупреждение. Заранее благодарим за любые дальнейшие предложения. Я новичок.UIAlertView 'устарел в iOS 9.0

UIAlertView 'устарел в iOS 9.0: UIAlertView устарел. Используйте UIAlertController с preferredStyle из UIAlertControllerStyleAlert вместо

Вот мой код:

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) 
    } 
} 
+0

Что не работает? Я вижу ваш код 'UIAlertView', но не вашу попытку' UIAlertController'. Существует множество учебных пособий. [Здесь] (http://nshipster.com/uialertcontroller/) является одним из них. –

+1

Обновите свой вопрос, пытаясь использовать 'UIAlertController'. Объясните, что у вас есть. И выполните некоторые поиски. Существует множество примеров использования 'UIAlertController'. – rmaddy

ответ

1

использование UIAlertController

Вот пример:

//Create the AlertController 
    let actionSheetController: UIAlertController = UIAlertController(title: "Alert", message: "Swiftly Now! Choose an option!", preferredStyle: .Alert) 

    //Create and add the Cancel action 
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in 
    //Do some stuff 
    } 
    actionSheetController.addAction(cancelAction) 
    //Create and an option action 
    let nextAction: UIAlertAction = UIAlertAction(title: "Next", style: .Default) { action -> Void in 
    //Do some other stuff 
    } 
    actionSheetController.addAction(nextAction) 
    //Add a text field 
    actionSheetController.addTextFieldWithConfigurationHandler { textField -> Void in 
     //TextField configuration 
    textField.textColor = UIColor.blueColor() 
    } 

    //Present the AlertController 
    self.presentViewController(actionSheetController, animated: true, completion: nil) 
0

Попробуйте что-то вроде этого ...

let sendMailErrorAlert = UIAlertController(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", preferredStyle: .Alert) 

self.presentViewController(sendMailErrorAlert, animated: true, completion: nil) 
0
let alertController = UIAlertController(title: "Could Not Send Email 
    ", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", preferredStyle: .Alert) 

Использование UIAlertController После инициализации добавьте действия в alertcontroller. UIAlertCOntroller - это подкласс UIViewController. Таким образом, вы можете использовать метод self.presentViewController show show на текущем контроллере.

Смежные вопросы