0
votes

I have a viewController (let's call it VC1), which is displayed when the application starts, it has a menu button that opens modalVC, in modalVC there are three buttons that open VC1, VC2, VC3 (at VC2, VC3 also have this menu button )

I run my application (on VC1), I press on the menu button (modalVC), turn on VC1.

It turns out that I have now two VC1 open? Because every time I press on VC1, is added to the memory of 1-2 mb. How can I remove them from memory?

Must somehow after selecting the controller menu (modalVC) to remove all that was earlier ..how?

The transition from the menu on the VC1, VC2, VC3 do so: UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController: VC1]; [self presentViewController: navController animated: YES completion: nil];

If i will push menu button and always select VC2 (10 times will do that) app will slow

i tried this after select VC in menu (modalVC)

NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
[allViewControllers removeAllObjects];
self.navigationController.viewControllers = allViewControllers;
1
it sounds like all user actions result in pushes onto the navigation stack, but no pops. "pop" is how to remove from a stack, and you should look at nav vc's handful of methods with "pop" in their names. it also sounds like you want your app to allow user to select between a few, single-instance vcs... the out-of-the-box container for that kind of app is a tabbar vc.danh

1 Answers

0
votes

Your menu implementation is flawed by design. You are creating new instances of each ViewController whenever the user taps on a button, instead of using the one you had already created before. A menu like that should be implemented using ViewController Containment. This way, the container ViewController will create the VC1 VC2 and VC3 whenever they are needed, and won't re-create them if they are already there.

To find out how exactly you're gonna do that, just read the section called "Implementing a Custom Container View Controller" in Apple docs