19

With the introduction of storyboard, I wouldn't select to create a .xib/.nib when I create a subclass of UIViewController, because I can just drag out a viewcontroller in interface builder and assign it to the new class.

So, with storyboard, when would i need to use the .xib/.nib file?

Thank you.

Besi
  • 22,579
  • 24
  • 131
  • 223
William Sham
  • 12,849
  • 11
  • 50
  • 67
  • ive never used storyboard but isnt it just like a wizard for creating apps or at least the views? i highly doubt there is any difference in the views it creates then ones manually created. i would bet those xib files are still there but hidden – owen gerig Dec 13 '11 at 19:47
  • It isn't in the file hierarchy, there isn't an actual file in the root folder. – William Sham Dec 13 '11 at 20:18

4 Answers4

33

Storyboards don't completely remove the need for NIB files. One common example is when creating subviews to go inside a UIScrollView. You can't create the subviews separately in a storyboard; instead you have to create separate NIB(s) for the subviews and attach them to the scroll view programatically.

In fact, on almost any occasion where you have a need for subviews which change at runtime you'll want to use separate NIBs.

Storyboards are great for certain kinds of apps, but for anything even remotely complicated the old way works very well still. An additional benefit is that they co-exist nicely. You can put placeholder views in your storyboard and fill them programatically with NIB-defined views later on.

Tim
  • 5,024
  • 2
  • 30
  • 58
  • + 1 for being concise, accurate, and to-the-point. Not to mention actually answering the question. – eric Feb 18 '13 at 16:39
11

I guess, storyboard contains the .xib/.nib files for all your views. It present relationships between them and helps you to avoid confusion if you have a LOT of views. Also it saves your time and nerves when writing code.

bragboy
  • 34,892
  • 30
  • 114
  • 171
Akki
  • 1,487
  • 14
  • 25
  • Thank you. Now I feel more comfortable as I see all these tutorial from pre-storyboard time talks about using .xib – William Sham Dec 13 '11 at 20:41
  • 5
    Before jumping into reworking your entire interface with storyboards, you may want to read Jonathan Wight's thorough description of issues he's had with the technology: http://toxicsoftware.com/uistoryboard-issues/ – Brad Larson Dec 15 '11 at 22:17
  • 1
    The URL mentioned in Brad Larson's comment seems to have moved, it's now http://toxicsoftware.com/uistoryboard-issues.html – JosephH Jan 23 '13 at 11:55
10

I have tried out storyboarding lately and I do have mixed feelings about its use:

Pro's

  • Convenience: You might have to write much less code. So you can for example show a static view without having to write any code.
  • Overview: You can quickly see how the ViewControllers relate to each other
  • Efficiency: For the simple use cases I find the Storyboarding much more efficient than "the old way".

    Example 1: Editor > Embed In > Navigation Controller and voilà, no more instantiating and configuring is required.

    Example 2: You can make "Prototype Cells" for TableView which speeds up the creation of static table views dramatically. AFAIK this is not possible with nib files

  • It's cool :-)

Con's

  • I find that the re-usability somehow suffers with storyboards. Although I can segue to a given ViewController from multiple points, it is still limited since in one case I might use the VC as a Popover and in another as a Master-ViewController.
  • Assuming that you are working in a big team and different people are changing different parts of your application, having one monolithic storyboard which you then have to merge might pose a big problem team-work-wise.
  • I really would like to have some mechanism to include or reference existing nib files into the storyboard which is currently not possible.

So considering these points I still find storyboarding very appealing but it makes sense to combine both approaches which is not really a big deal. Additionally, this technology it is still quite new so it might improve in the (near) future.

Community
  • 1
  • 1
Besi
  • 22,579
  • 24
  • 131
  • 223
4

If you use storyboards, you generally won't need to create separate .xib files. You can still use a .xib file if you want to -- it might be useful e.g. if you have a particularly complex view that you'd like to configure by itself. Most of the time, though, there won't be a need to do that.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • Don't you have to create nib files, when you want to re-use specific views. For example if you have some sort of rating view (4 out of 5 Stars), which you want to place in various places? – Besi Dec 21 '11 at 13:56