xcode 使用故事板的优点和缺点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9360826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:22:15  来源:igfitidea点击:

Advantages and disadvantages of using Storyboarding?

iosxcodecocoa-touchxcode-storyboard

提问by cvursache

I've been writing iOS apps for a while now and gradually went from doing the UI entirely programmatically to using the Interface Builder intensively. I'm now thinking about using the new Storyboarding feature for some of my new projects, but I don't have enough experience or knowledge with it to calculate the advantages and disadvantages of doing so. Can anybody give some examples or information about when using Storyboarding payed off and when it was a waste of time?

我已经编写 iOS 应用程序有一段时间了,并逐渐从完全以编程方式完成 UI 转变为密集使用界面生成器。我现在正在考虑在我的一些新项目中使用新的 Storyboarding 功能,但我没有足够的经验或知识来计算这样做的优点和缺点。 任何人都可以提供一些关于何时使用 Storyboarding 得到回报以及何时浪费时间的示例或信息?

采纳答案by tacos_tacos_tacos

Advantages of Storyboarding

故事板的优势

  • It's cool - suave way to design interfaces
  • Use of StoryBoardSeguesto identify navigation/modal relationships
  • If your app supports multiple devices, good way to organize different views (by storyboard file rather than naming, etc)
  • Nice for prototyping
  • Prototype UITableViewCellcan save time
  • 很酷 - 设计界面的温和方式
  • 使用的StoryBoardSegues识别导航/莫代尔关系
  • 如果您的应用程序支持多个设备,那么组织不同视图的好方法(通过故事板文件而不是命名等)
  • 很适合做原型
  • 原型UITableViewCell可以节省时间

Disadvantages of Storyboarding

故事板的缺点

  • It's a runtime feature, so I believe it is only available in iOS 5
  • StoryBoardSeguesare kind of rigid in my experience and you may make use of prepareForSeguea lot
  • Like IB, not very friendly with other display engines and toolkits
  • Makes it hard to share designs for a single view or set of views - you have to send all or nothing
  • 这是一个运行时功能,所以我相信它只在 iOS 5 中可用
  • StoryBoardSegues在我的经验中有点僵硬,你可能会使用prepareForSegue很多
  • 和IB一样,对其他显示引擎和工具包不太友好
  • 难以共享单个视图或一组视图的设计 - 您必须全部发送或不发送

These seem kind of superficial, I guess I haven't given it much thought... At first I was gung-ho about story boards, but now I've reverted to IB or even just programatic view configuration... The more I use them, the less I like them, and the more they feel like a gimmick/waste of time.

这些看起来有点肤浅,我想我没有考虑太多......起初我对故事板很感兴趣,但现在我已经恢复到IB甚至只是编程视图配置......我越多使用它们,我越不喜欢它们,越觉得它们是噱头/浪费时间。

Edit

编辑

I wrote this answer a few years ago. I have left it the same as before for posterity, although some points are likely no longer relevant (ie the fact that it requires iOS 5+).

几年前我写了这个答案。我把它留给后代和以前一样,尽管有些观点可能不再相关(即它需要 iOS 5+ 的事实)。

After some time, my opinion hasn't changed on storyboards. As others have mentioned, they're okay if you are working solo on an app with few views to manage, but they become a real pain with source control & collaboration. In addition, I prefer one-file-one-object, and storyboards obviously bundle stuff together (as does IB, but to a lesser extent).

一段时间后,我对故事板的看法没有改变。正如其他人所提到的,如果您在一个几乎没有要管理的视图的应用程序上单独工作,它们是可以的,但是它们成为源代码控制和协作的真正痛苦。此外,我更喜欢一个文件一个对象,并且情节提要显然将内容捆绑在一起(IB 也是如此,但程度较轻)。

If I were writing an app meant to be maintained for any serious length of time, I would go with programmatic view configuration over IB, but definitely IB over storyboards.

如果我正在编写一个需要长时间维护的应用程序,我会使用 IB 上的程序化视图配置,但绝对是 IB 上的故事板。

回答by Ray Fix

Another disadvantage with Storyboarding not mentioned is that merges can be very difficult if not impossible if there are conflicts.

没有提到的 Storyboarding 的另一个缺点是,如果存在冲突,合并可能会非常困难,如果不是不可能的话。

Update: It also occurred to me that it puts logic in two places. If your segue is not doing the right thing it might be because of an error in prepareForSegue or it might be because you named your segue incorrectly. Doing things programmatically is, in the end, not that hard.

更新:我还想到它把逻辑放在两个地方。如果您的 segue 没有做正确的事情,可能是因为 prepareForSegue 中的错误,或者可能是因为您对 segue 的命名不正确。最终,以编程方式做事并没有那么难。

回答by Travis M.

At the latest WWDC (2013) Apple Devs strongly recommend using storyboard and built in IB stuff to do most of your code for you instead of writing it by hand because you are much more likely to avoid deprecation and take advantage of feature updates via automated conversions.

在最新的 WWDC (2013) 上,Apple Devs 强烈建议使用故事板和内置 IB 的东西来为您完成大部分代码,而不是手动编写,因为您更有可能避免弃用并通过自动转换利用功能更新.

The lone disadvantage is the difficulty in allowing git collaboration on storyboards, as there will be conflicts on virtually every commit.

唯一的缺点是很难在 Storyboard 上允许 git 协作,因为几乎每次提交都会发生冲突。

If you are a solo programmer, you should always be using storyboards.

如果您是独立程序员,则应该始终使用故事板。

回答by Muhammad Zeeshan

I have learn the storyboarding by following the tutorials from the raywenderlich's website and there is a lot of stuff about the storyboard.

我已经按照 raywenderlich 网站上的教程学习了故事板,并且有很多关于故事板的内容。

Here is the link to site: http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

这是网站的链接:http: //www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

Advantages of storyboard:

故事板的优点:

1) Before you start developing app you can see all the screens of the app.

1) 在开始开发应用程序之前,您可以看到应用程序的所有屏幕。

2) You can visually see the relationship between each screen.

2)可以直观的看到各个画面之间的关系。

3) It can help to reduce the amount of the code specially in case of UITableView you can use prototype cells and static cells to design your TableView in storyboard.

3)它可以帮助减少代码量,特别是在 UITableView 的情况下,您可以使用原型单元格和静态单元格在故事板中设计您的 TableView。

4) In case if you have to work on someone else code you can get the better understanding of the flow of the app by viewing storyboard in short time.

4) 如果您必须处理其他人的代码,您可以通过在短时间内查看故事板来更好地了解应用程序的流程。

5) You can setup the user interface for iPhone 4 and iPhone 5 by applying the retina form factor from storyboard, without running the app again and again.

5) 您可以通过应用情节提要中的视网膜外形为 iPhone 4 和 iPhone 5 设置用户界面,而无需一次又一次地运行应用程序。

6) If you are doing client based work then some clients want to see the prototype of the app before start developing it, here storyboard helps you a lot.

6) 如果你在做基于客户端的工作,那么一些客户希望在开始开发之前查看应用程序的原型,这里故事板对你有很大帮助。

Disadvantages of storyboard:

故事板的缺点:

1) For storyboard you will need a big screen specially in case of iPad.

1) 对于故事板,您需要一个大屏幕,特别是在 iPad 的情况下。

2) I also experience a difficulty while copying views from other apps to storyboard.

2) 我在将视图从其他应用程序复制到故事板时也遇到了困难。

3) I also experience problems in storyboard when multiple developers work on the same project by using git repository.

3) 当多个开发人员使用 git 存储库在同一个项目上工作时,我在故事板中也遇到了问题。

By reading and understanding the advantages and disadvantages you can judge your self when to use storyboard.

通过阅读和理解优点和缺点,您可以判断自己何时使用故事板。

回答by ComSubVie

I have a similar background to you - I started with mostly building my iOS UI programmatically since IB was not really user-friendly, but lately decided to use IB more and more, since it is better for designing the UI and works fine for standard-elements.

我和你有类似的背景 - 我开始主要以编程方式构建我的 iOS UI,因为 IB 并不是真正的用户友好型,但最近决定越来越多地使用 IB,因为它更适合设计 UI 并且适用于标准 -元素。

With the new Xcode I switched to Storyboard, since they provide a full view of the application. It is possible to generate the complete UI (with all views) in a single File, which can be used for prototyping and which I can view my colleagues before writing the first code line. It is far better and easier than designing with photoshop or similar tools.

使用新的 Xcode,我切换到 Storyboard,因为它们提供了应用程序的完整视图。可以在单个文件中生成完整的 UI(包含所有视图),该文件可用于原型设计,我可以在编写第一行代码之前查看我的同事。它比使用 Photoshop 或类似工具进行设计要好得多也容易得多。

However if you use a lot of your own UI elements/controls or something using a different "engine" (cocos2d, OpenGL, etc.) it is usually better to generate the UI programmatically, since these "engines" are not really integrated with IB/Storyboards.

但是,如果您使用大量自己的 UI 元素/控件或使用不同“引擎”(cocos2d、OpenGL 等)的东西,通常最好以编程方式生成 UI,因为这些“引擎”并未真正与 IB 集成/故事板。

回答by Mohamed Emad Hegab

One Word (DON'T) One of the biggest disadvantages of storyboard aside from the git conflicts that make it impossible for two or more persons to work on it. but also if the project went so big and you have +40 screens , if you insane enough to move anything just one pixel in any view controller you have in the storyboard, you'll have a very huge compilation time, that you can build your app and make it run in more than 5 minutes, and of course don't let me start with archiving to give some one adhoc of the app .

一句话(不要)除了 git 冲突之外,storyboard 的最大缺点之一就是无法让两个或更多人一起工作。而且如果项目变得如此之大并且你有 +40 个屏幕,如果你疯狂到在故事板中的任何视图控制器中移动任何一个像素,你将有非常长的编译时间,你可以构建你的应用程序并让它在 5 分钟以上运行,当然不要让我从存档开始给应用程序一些临时的。

after this painful experience I totally fell back to the oldy goldy great xib files and deleted the storyboard file in a huge fire celeberation .

在这次痛苦的经历之后,我完全回到了古老的金色伟大的 xib 文件,并在巨大的火灾庆典中删除了故事板文件。