Search code examples
swiftuiviewcontrollerswift2segue

How to destroy instance of view controller after performing segue


I use performSegueWithIdentifier to navigate between views controllers

I have a tableView with multiple rows, when a row is actioned, i call a webViewController to play selected ressource with segue

performSegueWithIdentifier("Play", sender: nil)

Associate with :

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if(segue.identifier == "Play") {
        let detailVC = segue.destinationViewController as! WebViewController
        detailVC.courseToPlay = self.courseToPlay
    }
}

And, on WebViewController, i've a button to goBack on the list, whose i want to destroy instance of webViewController on goBack

I've not NavigationController in my storyBoard, so, this line doesn't work

navigationController.popViewControllerAnimated(true)

I use segue again to goBack :

performSegueWithIdentifier("closePlayer", sender: nil)

But each segue action instance a new view controller and they're never really free from memory, they seems to just be hiddens

eg : in Safari debugger i can see a lot of page and i can always interact with these in console

How to properly 'destroy' a view when scene change


Solution

  • If it is a modal segue you can use

    dismissViewControllerAnimated(true, completion: nil)
    

    To dismiss the webViewController instead of another segue