Unwind Segue Doesn't Work

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?

Answered by psynixis in 124830022

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.

Glad you got your code working!

Make sure the unwind function is defined on the parent view controller. If this doesn't work, check the name of your view controller class. Once, I changed the name of my view controller but forgot to change the class name, which caused an issue with my unwinding segue.

Unwind Segue Doesn't Work
 
 
Q