On Apr 5, 2010, at 6:04 PM, Frederick C. Lee wrote:

> Greetings:
>    I wish to preserve the state of an iPhone/iTouch application; which means 
> that I would like the application to continue deep down within a stock of 
> View Controllers at a particular view when I return to the application.
> 
>   Does this mean that I need to preserve the ID of a particular 
> viewController/position in the NSUserDefaults?   For example, I store a 
> unique identifier/pathway of a target in NSUserDefaults then navigate back to 
> that position upon return to the application?
> 
> 
> What is the recommended paradigm to handle this?
> 
> Regards,
> 
> Ric

Hi Frederick,

I've been giving some thought to the same question lately and here's what I've 
come up with.

For a UI that is heavy on drilling down a hierarchy of view controllers, I 
imagine the path from the application's root view controller to any other view 
controller as represented by an instance of NSIndexPath. So, for example, the 
index path 1.3.2 would represent going through the second VC from the root 
controller, then the fourth VC accessible from that, then the third VC 
accessible from that. (Recall that indices in an index paths are zero-based)

So, one could have an index path ivar in the application delegate which is 
updated every time a given VC is pushed into, or popped from, the navigation 
stack. Naturally, that ivar is saved when the application terminates and read 
when the application starts up.

Then, once it's read back in, it's just a matter of following the bread crumbs 
to the last visited view controller. Of course, one needs to make sure that 
this "automated" walk-through of the hierarchy has the same relevant effects as 
when the user did it, but not everything needs to be redone. For instance, 
animations that might happen in the intermediate view controllers need not be 
performed again, since the goal is to get back to the last visited view 
controller as quickly as possible.

I'm very interested in other people's take on this issue, since I have no idea 
if my solution is the best or even the recommended way of achieving the desired 
result.

Wagner_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to