iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

does PBRevealViewController handle deinit of VC's #52

Closed justdan0227 closed 6 years ago

justdan0227 commented 6 years ago

Does this library deinit viewcontrollers unlike SWReveal? I just noticed that all of my viewControllers are sticking around and looking for a more up to date drawer library for IOS.

iDevelopper commented 6 years ago

No, like SW, the library does not handle deinit or dealloc. View controllers (left, main, right) are removed from memory by ARC when they are removed from their parent view controller (i.e PBRevealViewController). If you want them not to be removed from memory you have to keep a strong reference to them.

justdan0227 commented 6 years ago

Ok but there is my issue. It appears that even a simple controller instantiated from the menu over and over again does not dealoc/deinit ?

iDevelopper commented 6 years ago

I will have a check

iDevelopper commented 6 years ago

Here is a sample. You can see that the "deinitializer" is called immediately before the class instance (Main or Second View Controller) is deallocated, each time you replace the main view controller. Here you can perform additional cleanup if needed.

PBRevealDeinit.zip

justdan0227 commented 6 years ago

Ok this look promising. Can you tell me why my button on my Main ViewController that is supposed to invoke the SecondViewController is somehow just calling deinit of the Second? PBRevealDeinit_dan.zip

iDevelopper commented 6 years ago

The menu is not open then the second view controller is not pushed and the main view controller is not replaced so the second view controller is deallocated immediately.

    @objc open func pushMainViewController(_ mainViewController: UIViewController, animated: Bool) {
        var operation: PBRevealControllerOperation
        if isLeftViewOpen {
            operation = .pushMainControllerFromLeft
        }
        else if isRightViewOpen {
            operation = .pushMainControllerFromRight
        }
        else {
            return
        }

        let fromViewController: UIViewController? = self.mainViewController
        self.mainViewController = mainViewController
        _pushFromViewController(fromViewController!, toViewController: mainViewController, operation: operation, animated: animated)
    }

In this case you have to replace the main view controller instead of pushing it:

    @IBAction func myButtonPressed(_ sender: Any) {

        let controller = storyboard?.instantiateViewController(withIdentifier: "SecondViewController")
        let nc = UINavigationController(rootViewController: controller!)
        //revealViewController()?.pushMainViewController(nc, animated:true)
        revealViewController()?.setMainViewController(nc, animated: true)
    }

PBRevealDeinit.zip

justdan0227 commented 6 years ago

ahhhh got it! Thanks.. so much easier than SWReveal!

iDevelopper commented 6 years ago

Great! I will close this issue. Feel free to open another one if needed.