Here is my code below. I keep getting the error: "Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior". Everywhere online says this code will work. Thoughts on why it doesn't work?
let alert = UIAlertController(title: "Alert: iCloud Disabled", message: "Go into Settings -> iCloud -> iCloud Drive and switch iCloud Drive to On.", preferredStyle: UIAlertControllerStyle.Alert)
let OKAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: {
(_)in
self.networkAlertDisplayed = true
self.performSegueWithIdentifier("unwindToController1", sender: self)
})
alert.addAction(OKAction)
self.presentViewController(alert, animated: true, completion: nil)
What do I need to do to get this code working?
Can you do the following test - it will hopefully show if you're doing something strange with your Storyboard:
1) Create a new project, and have two screens.
2) On the first screen create a button that segues to the second screen when tapped
3) On the second screen, create a button that shows your alert when tapped
Make the source code for the first view contoller be this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func unwindToController1(segue: UIStoryboardSegue) {
print("unwound")
}
}
And make the code for the second view controller be what I posted in my previous comment.
4) Set up your unwind segue as you normally do.
Then, see if that test project works.