MK4 MK4 - 3 months ago 17
Swift Question

Error in console using UIAlertAction Xcode 7.3 beta

I am trying to print the error to the user using alertview.
Here is my code :::

if error != nil{
let DisplayAlert = UIAlertController(title: "Error!!", message: error?.description, preferredStyle: .Alert)
DisplayAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
}


When I run the code I see the following in the console and I do not see any alert displayed to user.

"Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior"

What should i do to fix this issue.? Pls help.
Thanks !!!

LIH LIH
Answer

Looks like you have forgot to present the alert

if error != nil{
    let DisplayAlert = UIAlertController(title: "Error!!", message: error?.description, preferredStyle: .Alert)
     DisplayAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
    self.presentViewController(DisplayAlert, animated: true, completion: nil)
}
Comments