Hermann Klecker
Hermann Klecker

Reputation: 14068

Using subset of storyboard for a second target

I am going ot develop a full version, lite version and free version of an app. (or two of them at least)

In the past, without Storyboard, I just added another target and set a compiler variable and used #if/else/endif statements to manage the variances between the versions. All fine so far.

This time I used a storyboard for the first time. It has some 50 view controllers. And now I am facing the question how to deal with that. Especially as the full app is tab bar based and the lite version should go without tab bar (it will cover not more than the functionality corresponding to one of the tabs of the full version).

How can I deal with this? Do I need a second storyboard? Will I be able to reuse views from storyboard #1 in storyboard #2 and #3? Or can I at least use a second storyboard as starting point only and then branch into parts of storyboard #1? (Again, the lite app will mainly consist of functionality that is within one of the tabs of the full app).

Frankly I donnot even know where to start. That is why I cannot share what I have tried so far. Any hint is appreciated.

Upvotes: 3

Views: 1430

Answers (1)

Hermann Klecker
Hermann Klecker

Reputation: 14068

All right, finally I found a suitable way. Although I am not totally happy with it because it was not what I was looking for, it works and it provides me with a high degree of re-usage.

1) Create a new target in xcode.

2) Xcode will create a second set of storyboards.

3) The storyboards have per default the same names as the original ones but reside in different (newly created by xcode) and assigned one to each target.I renamed it because I need both storyboards in my second target.. Renaming it is not required if each target uses its own storyboard only. But in this case you should rename it. If you rename it then you need to assign the new name within the target's project settings. Works nicely.

4) In my case the storyboard for the free app basically consists of its root view controller and one regluar view controller wich seves me as some main menu for the user. In my case the full app is based on tabs and due to reduced funktionality and some more lean use case the free app is not.

5) This main menu view controller then will segue programmatically to view controllers of the other story board. For doing so it is essential that all IDs in the storyboard are properly set and unique (!). In my case this menu consists of a number of buttons. Each of them invokes an IBAction. You could of course us a table instead etc.

 - (IBAction)newMinutes:(id)sender
 {
     // Get the storyboard named secondStoryBoard from the main bundle:
     UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];

     // Load the view controller with its identifier string 
     // Change UIViewController to the appropriate class
     UIViewController *theTabBar = (UIViewController *)[secondStoryBoard instantiateViewControllerWithIdentifier:@"MinutesMenu"];

     // Then push the new view controller in the usual way:
     [self.navigationController pushViewController:theTabBar animated:YES];
 }

6) Once this view controller is up and running then it works nicely within its own storyboard and will perfectly segue to subsequent view controllers etc.

7) However, at some place I still need to make some variances. For those situations I set up two macros in each target's project settings. FREE and FULL are those macros. So I can compile slightly different code, such as programmatic segues, using the #ifdef construct.

#ifdef FULL 
  // do this
#else 
  // do that
#endif

or

#ifdef FREE
  // do this
#endif

Hope, that helps T.J. and others in the same situation.

Upvotes: 2

Related Questions