2

I have a UITabBarController based application. I want to launch a configuration guide - a series of views - the first time the application is launched. That of course have nothing to do with with the normal tab navigation and I want the configuration views to cover the entire screen.

I have a class that supports the UIApplicationDelegate protocol and I tried to launch my configuration view from the application:didFinishLaunchingWithOptions method with the following code:

UIViewController *vc = [[self.mainViewController storyboard] instantiateViewControllerWithIdentifier:@"StartupWelcomeViewController"];
[self.mainViewController presentModalViewController:vc animated:YES];

(the mainViewController is a reference to the UITabBarController)

Apparently application:didFinishLaunchingWithOptions is called before the viewDidLoad for the tab bar views. If I move my code above to a function that is called after the viewDidLoad it works.

I cannot find a method in the UIApplicationDelegate protocol or the UITabBarController class that is called after the viewDidLoad methods in the tab bar views.

Where is a good place to launch my configuration guide and how do I do it?

X Slash
  • 4,133
  • 4
  • 27
  • 35

1 Answers1

2

(Old question, but for the sake of archives...)

If you want your startup wizard to appear on top of the tab view controller, then the tab view controller should present it; you would do that from somewhere like viewDidLoad. If you don't like having that code in the tab bar controller then put it in e.g. the application delegate and just have the tab bar controller call it.

An arguably cleaner alternative is to have no automatically appearing view in your app, instead orchestrating everything from the application delegate - it checks to see if the configuration wizard has been run and chooses to show either that wizard, or the tab bar controller & thus the related UI. In either case, the instantiation code would retrieve the relevant named object from the storyboard in the manner shown in your question. The startup wizard would call back to the application delegate when it was finished using a very simple delegate protocol you'd design yourself, which would give you the cue needed to show the tab bar presumably by calling the same show-tabs method that'd be invoked whether the tab bar was shown immediately, or shown after configuration completed.

This second approach does mean your storyboard is doing less of the work and your code is doing more. In my experience so far, this seems to happen with a certain inevitability as an application matures and its functionality starts to extend beyond the relatively basic flow options provided by automated storyboard behaviour.

Footnote

  • You prevent a storyboard from showing any view at startup by turning off the Is Initial View Controller option in XCode's storyboard editor's attributes inspector (Command-Option-4) shown when you select whichever controller is currently used for this purpose. It'll be on the leftmost side of the storyboard editor area and have an arrow pointing to it that "fades in from nowhere" left-to-right. Once you do this you'll get a build warning, which is rather annoying; you may decide to add a dummy, blank view controller and set this as an initial view purely to avoid the warning.
Andrew Hodgkinson
  • 4,379
  • 3
  • 33
  • 43