Friday, 23 August 2013

How can I keep a view controller in memory after its popped from the stack?

How can I keep a view controller in memory after its popped from the stack?

This is an embarrassingly simple question, but I need to preserve a view
controller and my current solution is not a solution.
I have a slide out table view menu that lets me select a new view
controller to push to the forefront. When I select a view, it deallocs the
old main view controller to push the new one. Since 90% of my
functionality revolves around one view controller, I want it to stay in
memory so I don't have to constantly spend resources to allocate it and
either pull the last data source from core data or make a network request.
I naively tried to set a placeholder temporaryMainViewController and
assign it to my center view controller before it is assigned another VC,
but assigning the current main view controller to the
temporaryMainViewController simply assigns the address of the main view
controller- so when it's changed, so is my tempVC. Trying to copy the view
controller causes a crash.
So how can I effectively do self.temporaryMainViewController =
self.currentCenterViewController; where the temp controller is assigned by
value of object and not value of address?

No comments:

Post a Comment