Alexi Groove
Alexi Groove

Reputation: 6686

Conditional application launch view

My app is driven by a UITabBarController embedded with a UINavigationController for each individual view within each active tab.

When the app is launched the first time, I'd like to present a separate settings view without a visible TabBar. After the user has completed the setup, they'd be taken to the main view with the TabBar. Also, once configured, the initial configuration view won't be accessible again from within the app although there will be a separate settings section that the user can modify their preferences.

What's a good pattern for doing this?

Upvotes: 1

Views: 286

Answers (2)

Dan Lorenc
Dan Lorenc

Reputation: 5394

You should create a settings completed variable inside NSUserDefaults upon the completion of the settings. If this variable is unset, you know it's the first run.

In your AppDelegate, before you instantiate the UINavigationController, check for the settings variable. If it's not there, take the user to a settings view. Upon completion, remove the settings view, and resume normal code:

BOOL settingsDone = [[NSUserDefaults standardUserDefaults] boolForKey:@"settingsComplete"];

if (settingsDone){
    SettingsView *mySettingsView = [[SettingsView alloc] init];
    [self.window addSubView:mySettingsView.view];
}

//Set up navigationcontroller here

-(void)settingsDone{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"settingsComplete"];
    for (UIView *view in self.window.subviews){
        [view removeFromSuperView];
    }
}

Just hook the done button in your settings view up to the settingsDone method.

Upvotes: 1

Randolpho
Randolpho

Reputation: 56391

Create a configuration setting that the user cannot modify. Call it "FirstRun" or something similar. Set it by default to true. When the user sets their settings for the first time, set it to false.

In your startup code, check the setting and, if true, show your initial settings page.

Upvotes: 1

Related Questions