I have write my custom alert view controller.But,I am having error at calling my alert controller from other view controller.It show me the error that I described below.
I see you made as subclass, but in the UIAlertController documentation is written:
The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
I would recommend you do not go against it. If you need something very custom better to use UIViewController and display with custom behavior.
Change your method like so:
func displayLoadingAlert(viewController: UIViewController?) -> UIAlertController {
var controllerToPresent = viewController
if controllerToPresent == nil {
controllerToPresent = self
}
// Most of your code
controllerToPresent.presentViewController(loadingAlertController, animated: true, completion: nil)
return loadingAlertController
}
Then when you're calling the alert:
loadingAlertController.displayLoadingAlert(self)
Alternatively: Rename the method displayLoadingAlert to loadingAlert
Remove the line:
self.presentViewController(loadingAlertController, animated: true, completion: nil)
then when calling insidethe showAlert() method
let loadingAlertController = loadingAlertController.loadingAlert()
self.presentViewController(loadingAlertController, animated: true, completion: nil)