views:

40

answers:

2

Is there a way for me to check which view the user was in when the application is about to quit? I want to make sure that once the app starts again that view will be the first thing the user sees, so I'm guessing this is the best way to go about doing it.

A: 

Ask the view controller for its current view assuming you have a reference to it in your app delegate or can somehow get it

Jose
A: 

I don’t think there’s a system support for that. Which means we should look for a decent manual solution. Maybe you could derive all your views from a common ancestor that will have an identification property and will mark itself as the current view when coming on screen? (There’s a willMoveToWindow: method you could use.) The saving could be something simple:

- (void) willMoveToWindow: (UIWindow*) window
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setInteger:self.tag forKey:@"currentView"];
    [super willMoveToWindow:window];
}

And maybe it would be cleaner to do this in the controller (viewWillAppear?). A matter of taste, I guess.

zoul