Question

I'd like to have a view with instructions on how to use my app show up on the first time the app is opened. I have handled the problem of the only showing this view on the first startup using NSUserDefaults, but I am having trouble getting the view to display the way I want it to modally, not as the rootViewController. Here is my AppDelegate.m code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];

    self.window.rootViewController = self.viewController;

    BOOL hasShownStartup = [[NSUserDefaults standardUserDefaults] boolForKey:kAppHasShownStartupScreen];

    if (!hasShownStartup) {
        [self showInstructions];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

- (void)showInstructions
{
    NSLog(@"showing instructions");
    InstructionsViewController *howToView = [[InstructionsViewController alloc] initWithNibName:@"InstructionsViewController"
                                                                                     bundle:nil];
    self.instructionsViewController = howToView;
    [howToView release];
    UINavigationController *howtoNavController = [[UINavigationController alloc]
                                             initWithRootViewController:self.instructionsViewController];
    self.instructionsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self.viewController presentModalViewController:howtoNavController animated:NO];
    [howtoNavController release];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kAppHasShownStartupScreen];
}

I want my rootViewController to remain self.viewController. I want to be able to click 'Done' on the instructionsViewController nav bar to transition back to the rootViewController. Executing the code as written never shows the instructions view. The only way I can see instructionsViewController is if I change the line [self.viewController presentModalViewController:howtoNavController animated:NO]; to self.window.rootViewController = self.instructionsViewController; but this is obviously not what i want (unless I could modally transition back to viewController).

Hopefully I've made it clear enough what I am trying to accomplish. Thanks in advance.

Was it helpful?

Solution

Try moving [self showInstructions]; to applicationDidBecomeActive: instead.

OTHER TIPS

Try putting the [self showInstructions] after [self.window makeKeyAndVisible]:

[self.window makeKeyAndVisible];

if (!hasShownStartup) {
    [self showInstructions];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top