I guess this should work, but mind that your app might run out of
memory if you cache a lot of views in the memory. Also keep in mind
that while the application is in suspended mode iOS may purge the
memory of the application and you will have to reload the views
anyways.

The normal approach is as you said yourself to create the view when
needed and dispose of it when it is not needed anymore. I am not sure
what the time consuming part of your views are, but usually my views
load instantly and the loading of the data to be put into the views is
what consumes most of the time.

So maybe a better approach to this could be to save the state of the
data in the view rather than the view itself. If it is really the view
that is taking that much time to load, then try to see if it can be
optimized.

On Thu, Jun 21, 2012 at 1:11 PM, victoria <[email protected]> wrote:
> Dear list,
>
> Short version: What's the correct way to load a UIViewController when the
> application starts, and then restore it (much) later?
>
> *
>
> I found creating UIViewControllers with somewhat complex Views to be a
> fairly expensive operation, so instead of just creating and pushing them
> onto the Navigator when needed, I had the idea to load all heavy views into
> a simple object cache when the app starts (with a nice loading screen), and
> then push/pop them at will while keeping them in memory. It works something
> like this:
>
> 1 AppStartUp
> |--- cache["finalView"] = new ComplexViewController();
> |--- push Menu A onto the navigator
> |
> 2 Menu A Controller
> | --- user makes some kind of selection
> | --- (cache["finalView"] as
> ComplexViewController).UpdateViewWithSelectionFromMenuA()
> |---  push Menu B onto the navigator
> |
> 3 Menu B Controller
> | --- user makes some kind of selection
> | --- (cache["finalView"] as
> ComplexViewController).UpdateViewWithSelectionFromMenuB()
> |---  push cache["finalView"] onto the navigator
> |
> 4 ComplexViewController
> | --- OMG Ponies!
>
>
> This method at first seemed to work great, and made the transition between
> Menu B and ComplexViewController *a lot* smoother. However, things started
> to fall apart recently with stuff going missing from the views in the cache.
> So, I started adding lots of SetNeedsDisplay() in their ViewWillAppear
> methods, and this somewhat worked - except for UITables. And some custom
> controls. I'm fairly certain I've gone down the wrong path here, so are
> there any best practices for doing what I'm trying to accomplish?
>
> Any help or hints would be much appreciated!
>
> / V
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/Correct-way-to-cache-and-restore-a-UIViewController-tp4655514.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch



-- 
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to