Question

I have used Cocos2D for a few months. I use:

MyCCScene *sceneToRun = [MyCCScene node];
[[CCDirector sharedDirector] replaceScene:sceneToRun];

This loads the new scene, cleans the previous scene from memory, then displays the new scene. Pretty straightforward.

Question: Is there something similar to this in UIKit?

-Modal segues keep the old ViewController in memory, their purpose is different.

-Push segues work in UINavigationControllers only.

I think the way to go is to implement my own Container ViewController which handles its child ViewControllers and memory the way I want. http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW81

But I am not entirely sure. Isn't there a more straightforward method? This looks like a huge overkill for such a simple and obvious thing.

Was it helpful?

Solution

I might have found a nice solution. One should use a UINavigationController, and manage its viewContollers property (which is the stack of UIViewControllers) manually. After (or before) the new UIViewController loaded, you can delete the old UIViewController from the stack, and thus purge it from the memory.

This post helped: How can I pop a view from a UINavigationController and replace it with another in one operation?

This way you can make a program flow, where only when UIViewController is in the memory at a time, and you replace them when you need a new UIViewController.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top