Does storyboard eliminate the need for .nib

拟墨画扇 提交于 2019-11-27 13:36:32
Akki

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.

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.

Besi

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!