Question

i have a question for you. I'm working on this app that has a walkthrough/tutorial screens and also login ones. On each of this screens there is a button to skip this part and go directly to use the app, without completing the registration (you know, so that people can test it before signing-in).

Controllers as seen in the Storyboard

As you can see i'm using Storyboards. The NowPlaying04 ViewController is actually the app itself. Obviously, when the user will be a registered one, i should also be able to jump right back to that screen, skipping the walkthrough and signin process.

The first question is: how is the best way to structure this?

The second quesion is: how i can make a ViewController outside that Navigation controller. Cause as you can see now, the NowPlaying04 ViewController inherits the top navigation bar. Which is a thing that i don't want. I don't need that.

I hope that you have understood my question. I'll appreciate any help. Programmatically or by dragging stuff around, i'm ok with all the solutions. The important thing is that it works correctly! :-)

Was it helpful?

Solution 5

So I maybe found a solution to this issue, using the AppDelegate.m. If you're using Storyboards, you don't need to import in the AppDelegate.h the ViewController classes, cause you're referencing them using StoryboardID. It looks something like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    BOOL userLoggedIn = NO;
    if (userLoggedIn) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"NowPlaying04"];
        [self.window setRootViewController:controller];
    } else {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"Start00"];
        [self.window setRootViewController:controller];
    }
    [self.window makeKeyAndVisible];

    // Override point for customization after application launch.
    return YES;
}

Obviously you'll need to set identifiers on the view controllers through the InterfaceBuilder/Storyboard properties. Setting a different value to the BOOL variable userLoggedIn the app loads with the relative rootViewController.

Now the Storyboard looks like this:

Storyboard after edit

Which is much more organized. isInitialViewController is flagged on the NowPlaying04 screen. But the AppDelegate decides if to go to it or rather switch to the NavigationController (with ID Start00), based on the isLoggedIn BOOL variable.

Thanks to @НаильГалиаскаров for idea of using different rootViewControllers.

OTHER TIPS

If you just want to hide the navigation bar, but this code to your ViewController.m:

- (void)viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}

To jump to a specific ViewController you can use this code:

NSInteger index = -1;
NSArray* arr = [[NSArray alloc] initWithArray:self.navigationController.viewControllers];
for(int i=0 ; i<arr.count ; i++)
{
    if([[arr objectAtIndex:i] isKindOfClass:NSClassFromString(@"Your_ViewController_Class_Name")])
    {
        index = i;
    }
}
[self.navigationController popToViewController:[arr objectAtIndex:index] animated:YES];

Question 1:

You can set the skip button's implementation to navigate you to the NowPlaying04 view controller.

        UIButton* skipButton    =   [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [skipButton addTarget:self action:@selector(skip) forControlEvents:UIControlEventTouchUpInside];


-(void)skip
{
    NowPlaying04* nowPlayingController  =   [[NowPlaying04 alloc] init];
    [self.navigationController pushViewController:nowPlayingController animated:YES];
}

Question 2:

Set the navigation bar hidden in NowPlaying04. In the init method or viewWillAppear method of NowPlaying04, just set the navigationbar hidden.

navBar.hidden = YES; 

@user1447316, I am glad that you liked my idea. However, I would rather use standarduserdefaults instead of local variable userLoggedIn. Saving this way is great when you want to save small amounts of data which you need even after user closed your app such as High Scores, Login Information, and program state.

You can save data once user logged from any place in your application by:

NSNumber *userLoggedIn = [NSNumber numberWithBool:NO];
[[NSUserDefaults standardUserDefaults] setObject:userLoggedIn forKey:@"log"];

And then you can check by retrieving:

  NSNumber *userLoggedIn = [[NSUserDefaults standardUserDefaults]objectForKey:@"log"];
  if ([userLoggedIn boolValue]){
         //user logged
  }

e.x. This nice technique will allow you even to detect your first launch and show to user some tutorial :)

If i were you I would present the register VCs as a modal.

if (!registered){
     [nowPlaying04  presentViewController:registrationNav animated:YES completion:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top