-2

I have a project, with a lot of view controllers, navigation- and tab bar controllers.

How can I add a "tutorial screen" to my app, which would run before the main screen appears? I can't find a way to do this, but I don't want to re-make the whole app just because of it.

Is there a solution for it?

Thanks!

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
lpasztor
  • 157
  • 13

1 Answers1

1

It depends on how your views are setup, if you use storyboards etc, but the usual thing to do this sort of thing is in AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   TutorialViewController *tutorialViewController = [[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:nil];
   self.window.rootViewController = tutorialViewController;
   [window makeKeyAndVisible];
   return YES;
}

-(void) loadFirstView {
    FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    self.window.rootViewController = firstViewController;
}

And in your TutorialViewController have a call to AppDelegate to change the window.rootViewController to your FirstViewController.

//TutorialViewController.m
-(void) showFirstView { 
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate loadFirstView];
}
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Vrasidas
  • 2,085
  • 1
  • 17
  • 23
  • Thanks! I'm going to try it out! If I won't be able to solve it, I'll come back for help, thanks! Could you please write down also that "call to AppDelegate"? – lpasztor Jan 06 '14 at 19:20
  • Thank you! It's very kind from you! – lpasztor Jan 07 '14 at 13:08
  • Unfortunately I get an error message: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle ... (loaded)' with name 'TutorialViewController''. On the storyboard the class "TutorialViewController" is selected for the View Controller of it, and the .h file of it contains the "initWithNibName" section as well, so it should work... but it doesn't. And for this line I received an error message: [window makeKeyAndVisible]; , so I corrected it to [self.window makeKeyAndVisible]; – lpasztor Jan 07 '14 at 16:14
  • Strange... When I don't use storyboard to add the ViewController, but I create the .xib file as well, it's working like a charm... Can I somehow make it work with storyboard as well? – lpasztor Jan 07 '14 at 16:19
  • Yes, it seems, I can't mix using the storyboard and using the .xib file. After the app starts, the .xib file (TutorialViewController) loads successfully, but when I click the button on it (which calls the showFirstView method), I got the 'Could not load NIB in bundle ...' error message... Any idea? – lpasztor Jan 07 '14 at 16:28
  • Sorry for these too many posts... Finally I could solve it by using storyboard: [link](http://stackoverflow.com/questions/13430179/appdelegate-rootviewcontroller-and-presentviewcontroller) – lpasztor Jan 07 '14 at 17:36
  • Yes it's a bit different with storyboards, glad you worked it out. :) – Vrasidas Jan 08 '14 at 07:11