Gerard G
Gerard G

Reputation: 3463

Tutorial screens for app

Hi I have found an awesome tutorial to show an overview of my app. how would you return back to the main app after this tutorial view has been viewed? Here is the location of the tutorial and all the source code.

My app views are in storyboard and I have a navigationcontroller in which my rootviewcontroller is held. I'm hoping to return to the rootviewcontroller of the navigation controller after the last page of the tutorial view is displayed. Thank you if you can help.

enter image description here

Here is my storyboard: The code I used to load the tutorial is this in AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     /*  This loads up the xib but I can't get back to the storyboard rootViewController */
    if (tutorialHasBeenSeen == false) {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.appViewController = [[APPViewController alloc] initWithNibName:@"APPViewController" bundle:nil];
        self.window.rootViewController = self.appViewController;
        [self.window makeKeyAndVisible];
        tutorialHasBeenSeen =TRUE;

    }


    return YES;
}

Would I try to pop to the rootView in the AppViewController.m in the method:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {

    NSUInteger index = [(APPChildViewController *)viewController index];

    index++;

    if (index == 5) {
        return  nil;
    }
        return [self viewControllerAtIndex:index];

}

Upvotes: 0

Views: 986

Answers (1)

CoderPug
CoderPug

Reputation: 918

Have you tried using

[self.navigationController popToRootViewControllerAnimated:YES];

EDIT

Now that I see what you are trying to do, I would recommend changing your approach: Instead of choosing if you should present the Tutorial in the didFinishLaunchingWithOptions method in the application delegate, why don't you always start on your application's First view controller, and here determine if the user should be displayed with a Tutorial or not, in that way you can invoke the Tutorial view controller inside your First view controller in your established navigation way of displaying hierarchical content.

enter image description here

The reason that you can't go from Tutorial to your First view controller is because you are assigning the Tutorial as your window view controller directly from the app delegate. So there is no way of going 'back' from Tutorial to your First view controller, to fix this I can think on two options,

  • At a desired moment change the window view controller of your application to be your First view controller instead of the already assigned Tutorial view controller. Which, as you may be guessing, is a tricky and just not clean way of doing this.
  • Set up a proper navigation hierarchy in your app, so First view controller should present your Tutorial view controller. And after, at a desired moment you simply dismiss or pop your Tutorial and get back to your First view controller.

As a conclusion,

1.Don't present your Tutorial from the AppDelegate, so leave the following method clean or as necessary but to perform other actions.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

2.From the view controller that will be your First view controller, invoke your Tutorial using segues or by code applying your desired logic for determining when a user should see the tutorial. If done properly when the app starts and the Tutorial appears it will be invisible that you are first displaying the First view controller

3.From your Tutorial view controller and at the desired moment dismiss or pop (will depend on your navigation) your view controller so you can go back to the First view controller

Upvotes: 1

Related Questions