Search code examples
iosmemoryuiviewcontrollerpresentmodalviewcontroller

Remove UIViewController from memory after Modal Segue


I'm On UIViewController 'A'. I'm presenting(Modally - Cross Dissolve) UIViewController 'B'.

After 'B' is presented, When i touch/tap the View, TouchesBegan of 'A' is triggered. So i figured i need to remove 'A' from memory after 'B' is presented.

I tried :

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "gameLevel"
        {
            if let viewController: ViewController = segue.destinationViewController as? ViewController {

                self.dismissViewControllerAnimated(false, completion: nil)
            }
        }
    }

Dosent seem's to work. Any suggestion how to remove 'A' from memory after i moved to 'B'?


Solution

  • I don't see why you should. If you are presenting a view controller, your user experience design should let the user go back to it. This is intended design; don't use presentViewController:animated if you don't want this experience.

    Furthermore, there is no hack in the SDK to do this either. This will be very apparent to you if you check the documentation, the presentingViewController is a strong reference.

    What you may want is to remove all the view hierarchy and set rootViewController property of your app delegate. You may not get the animation; but the underlying view controller might get deallocated.