3

I have read a lot about creating a lite and a paid version with Xcode and in my app I am using multiple targets and preprocessor macros as described in this Stackoverflow post. However, I don't know how to handle different targets with a Storyboard.

For example, in my storyboard I have a table view controller with static cells. In the paid version it has four cells, in the lite version has one extra cell whereas the rest of the storyboard remains unchanged. Is there a way to achieve that kind of behavior?

(Creating a new storyboard for the lite version (or duplicating it) is not an option for me as I have dozens of view controllers and 98% of the views and UI elements are identical in both versions. It would make the project difficult to maintain.)

Community
  • 1
  • 1
Mischa
  • 15,816
  • 8
  • 59
  • 117

1 Answers1

2

For example, in my storyboard I have a table view controller with static cells. In the paid version it has four cells, in the lite version has one extra cell whereas the rest of the storyboard remains unchanged. Is there a way to achieve that kind of behavior?

If you hadn't boxed yourself in by using a static table, this problem wouldn't have arisen in the first place; you'd be configuring the table in code, which can be conditional — end of issue.

As things stand, you'll need two different scenes in the storyboard, one for the paid version, the other for the lite version. Then:

  • If this scene is reached by a segue, you'll need two different segues that reach this scene, and you'll decide in code which one to trigger (and trigger it in code, not automatically).

  • If this scene is the initial view controller, you'll need to instantiate it initially in code rather than letting UIApplicationMain do this for you. Or, in that case, use two different storyboards for just this one scene, and then segue to another storyboard.

(And do keep in mind that multiple storyboards are a great way to organize your scenes in any case. I don't necessarily mean multiple alternative storyboards; multiple sequential storyboards can keep your storyboard from becoming overly complex. It sounds to me from your question as if all you need to do is understand how storyboards work - they are not magic, you know - and be more nimble in your use of them. Your entire deer-in-the-headlights fear of duplicating your storyboard - "I have dozens of view controllers" - suggests you've already gone way too far down the wrong road. Programming is like solving a Rubik's Cube: if you're in the middle of it and your response to someone trying to change something is "don't touch it!", you're doing it wrong.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    So basically you're saying there is no way to hide an individual UI element within a scene for a particular target? Of course I could duplicate a scene, add that one extra table view cell and create two segues that I trigger in my code depending in the target. But it seems little cumbersome to me because whenever I change the layout of the original scene I will have to perform the same changes on the duplicated scene as well (which is what I was trying to avoid by using different targets in the first place). – Mischa Sep 30 '14 at 17:12
  • Btw: I agree with your philosophical note - any code or storyboard should ideally be designed in a way that allows easy modifications. But what is the advantage of having multiple storyboards in project? Can you give me a hint where I can read more about that? – Mischa Sep 30 '14 at 17:21
  • 1
    "So basically you're saying there is no way to hide an individual UI element within a scene for a particular target". No, of course I'm not saying that. But your example is of a _static table_, which is configured purely in a storyboard. If you had used a normal dynamic table this would have been much simpler, because then its datasource would dictate _in code_ how many cells it has - and code can be conditional. Another example, perhaps, of depending too much on a storyboard: he who lives by the storyboard, dies by the storyboard... – matt Sep 30 '14 at 17:23
  • "Can you give me a hint where I can read more about that?" Various WWDC videos have talked about this since storyboards were introduced; I'm not going to research their names for you. – matt Sep 30 '14 at 17:24
  • My point is that you've boxed yourself in. My answer can only deal with the box. It would be much better, in my opinion, to break out of the box. – matt Sep 30 '14 at 17:27
  • Again, I agree with you but you can only break out of a box if you have a fundamental understanding of that box (or speaking without metaphors in this case: when you have a deep understanding of how storyboards are meant to be used) - and I'm still in the process of acquiring that knowledge. I didn't mean to ask you to do the research for me. Just thought you might have a link at hand. I am updating my table view in order to make it dynamic. Thanks for your help! – Mischa Sep 30 '14 at 17:45
  • 1
    At the moment, to get from a view controller in storyboard A to a view controller in storyboard B, you have to respond manually (e.g. to a tap or some similar stimulus) in view controller A by instantiating view controller B and getting it into the interface, in code. That's not hard - after all, there used to be no storyboards at all and we all coped perfectly well - but, just FYI, I have reason to suspect that it will eventually become possible to segue _automatically_ from one storyboard to another. – matt Oct 02 '14 at 17:30