Question

I recently work on a tutorial for my app. I created the tutorial with this Tutorial:

http://www.appcoda.com/uipageviewcontroller-tutorial-intro/

I created a "button" which brings the user back to the rootViewController, in this case the TabBarController. Problem is: with this tutorial I made a extra storyboard for the tutorial. So how can I go back to the original rootViewController(TabBarController) with the button?

Code:

- (IBAction)start:(id)sender {
        UIViewController* backToRootViewController = [[UIViewController alloc] initWithNibName:@"TabBarController" bundle:[NSBundle mainBundle]];
        [self.view addSubview:backToRootViewController.view];
}

This does not work, too

- (IBAction)start:(id)sender {
           [self.navigationController popToRootViewControllerAnimated:YES];
    }

EDIT

To open the tutorial at the first start:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
if (!isAccepted) {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[APPViewController alloc] initWithNibName:@"APPViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
}

APPViewController is the Tutorial

EDIT

After the help of johnnelm9r the current code is this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"main" bundle: nil];

    IntroViewController *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"IntroViewController"];

        BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
        if (!isAccepted) {
            [self.window.rootViewController presentViewController:introViewController animated:NO completion:nil];
        }

But now, sadly, the app crashed and the error is:

Application tried to present a nil modal view controller on target <UITabBarController: 0x175409d0>.'

and also a warning: Incompatible pointer type assigning to 'ViewController' from 'UIViewController' in AppDelegate

Was it helpful?

Solution

*****UPDATE****

I uploaded a sample project to demonstrate what I mean. You can find it here: github link Good luck!

**** EDIT

After talking with you more I'd suggest trying to use something similar to this code in your viewDidAppear method of whatever view controller runs the first tab of your tabbarcontroller (obviously you want your own class name where I have IntroViewController):

BOOL didShowIntro = [[NSUserDefaults standardUserDefaults] boolForKey:@"showIntro"];

IntroViewController *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"IntroViewController"];

if (didShowIntro)
    {
    [self presentViewController:introViewController animated:NO completion:nil];
    }

and then just pop the presented controller from your button in the tutorial like so:

[self dismissViewControllerAnimated:NO completion:nil];

Just remember to set your user defaults to no when you press the button in your tutorial view controller. And make sure you are going from tabbarcontroller to navigationcontroller as a relationship segue and then to the view controller you want to show after the tutorial as a root. Just to be clear: there should be no connection to the tutorial view controller on your storyboard.

Just to be extra clear: your storyboard should have the navbarcontroller as your initial view controller connected to a navigationcontroller connected to a view controller and another view controller not connected to anything. :) And make sure you delete the code in the delegate.

OTHER TIPS

To go to rootViewController

[self.navigationController popToRootViewControllerAnimated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top