不能完全解雇我以前的alertcontroller

我试图使用一个单一的警报控制器,其中包括多个警报显示function和一个解雇function。但我在我的控制台有这个警告 ,我的其他警报不显示。我想知道为什么?和解决scheme。

这是我的警报控制器

import UIKit class MyAlertViewController: UIViewController { var myAlertController : UIAlertController! override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func displayLoadingAlert(viewController: UIViewController?) -> UIAlertController { var controllerToPresent = viewController if controllerToPresent == nil { controllerToPresent = self } //create an alert controller myAlertController = UIAlertController(title: "Loading...", message: “We are receiving data,please wait“, preferredStyle: .ActionSheet) controllerToPresent!.presentViewController(myAlertController, animated: true, completion: nil) return myAlertController } func connectionErrorAlert(viewController: UIViewController?) -> UIAlertController { var controllerToPresent = viewController if controllerToPresent == nil { controllerToPresent = self } //create an alert controller myAlertController = UIAlertController(title: "Not Connected", message: “No internet Connection”, preferredStyle: .Alert) let defaultAction = UIAlertAction(title: "OK", style: .Default,handler:nil) myAlertController.addAction(defaultAction) controllerToPresent!.presentViewController(myAlertController, animated: true, completion: nil) return myAlertController } func requestTimeOutErrorAlert(viewController: UIViewController?) -> UIAlertController { var controllerToPresent = viewController if controllerToPresent == nil { controllerToPresent = self } //create an alert controller myAlertController = UIAlertController(title: "Request Time Out", message: “Please Click Retry”, preferredStyle: .Alert) let defaultAction = UIAlertAction(title: "OK", style: .Default,handler:nil) myAlertController.addAction(defaultAction) controllerToPresent!.presentViewController(myAlertController, animated: true, completion: nil) return myAlertController } func dismissLoadingAlert(){ myAlertController.dismissViewControllerAnimated(true, completion: nil) } } 

我使用dismissLoadingAlert()当我从API获得结果。但是,当我没有得到从API.i的结果用于从我的协议做这个委托方法。

 func didNotReceiveAPIResults(results: Bool,error:NSError){ dispatch_async(dispatch_get_main_queue(), { // This condition will be enter if we dont get the results and show user with alert. if (results) { // I have done dismiss first data receiving alert,what do i doing wrong? self.myAlertController.dismissLoadingAlert() if error.localizedDescription == "The Internet connection appears to be offline."{ self.myAlertController.connectionErrorAlert(self) self.carTableView.hidden=true self.retryButton?.hidden=false self.retryButton?.enabled=true } if error.localizedDescription == "Request Time Out."{ self.myAlertController.requestTimeOutErrorAlert(self) self.carTableView.hidden=true self.retryButton?.hidden=false self.retryButton?.enabled=true } }else{ self.myAlertController.displayLoadingAlert(self) self.retryButton?.hidden=true self.retryButton?.enabled=false self.carTableView.hidden=false self.carTableView.reloadData() } }) } 

你走错了路。 你不应该inheritance这个控制器。

UIAlertController类旨在按原样使用,不支持子类。 这个类的视图层次是私有的,不能被修改。

如果您需要一个便利的类,请使用呈现dynamicUIAlertController实例的NSObject子类重构。