xcode iOS Storyboards 我应该使用它们还是不使用它们?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13889034/
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-15 02:20:01  来源:igfitidea点击:

iOS Storyboards Should I use them or not?

iosxcodestoryboarduistoryboard

提问by EGHDK

I am new to iOS development (No apps created yet), but I ask for advice from my friend that has really high rated apps on the market. He said not to use storyboards.

我是 iOS 开发的新手(尚未创建应用程序),但我向我的朋友寻求建议,他们在市场上拥有非常高评价的应用程序。他说不要使用故事板。

As much as I want to take his advice, they seem really helpful.

尽管我很想接受他的建议,但他们似乎真的很有帮助。

  • Is this something that can cause problems for my app in the future?
  • Is there any reason I may want to not use storyboards?
  • 这是否会在将来给我的应用程序带来问题?
  • 我有什么理由不想使用故事板吗?

Coming from an Android background, I don't see why I should use them.

来自 Android 背景,我不明白为什么我应该使用它们。

回答by Simon

I'd recommend against using either storyboards or Interface Builder.

我建议不要使用故事板或界面生成器。

  • You'll learn Objective-C faster if you spend more time using it. Switching between IB and code, you'll have two things to learn. The context switching will still slow you down later on.
  • Nibs and storyboards are big XML files that don't play well with source control; if you're working on one at the same time as someone else, you willget merge conflicts.
  • You can't see everything that's going on at once in IB, so it's hard to track down things like layout problems.
  • You can't search or replace in IB the way you can in code
  • Nibs and storyboards put your view logic in your controllers. Whether that's a problem for you depends on how much of an MVC purist you are.
  • If you want to port your apps to/from Android, IB will make it much harder.
  • 如果你花更多的时间使用它,你会更快地学习 Objective-C。在 IB 和代码之间切换,您将有两件事要学习。上下文切换稍后仍会减慢您的速度。
  • Nibs 和 storyboards 是大的 XML 文件,不能很好地与源代码控制配合使用;如果您与其他人同时进行一项工作,则会出现合并冲突。
  • 您无法在 IB 中立即看到发生的所有事情,因此很难追踪布局问题之类的事情。
  • 您不能像在代码中那样在 IB 中搜索或替换
  • 笔尖和故事板将您的视图逻辑放在您的控制器中。这对您来说是否有问题取决于您是 MVC 的纯粹主义者。
  • 如果您想将您的应用程序移植到/从 Android 移植,IB 会让它变得更加困难。

This all comes from experience. I started out running a small software team developing iOS apps using IB (storyboard wasn't out yet) and within a year it had caused so many problems that I'd had to forbid its use. Our productivity went way up when we stopped using it.

这一切都来自经验。我开始运行一个使用 IB 开发 iOS 应用程序的小型软件团队(故事板还没有出来),一年之内它引起了很多问题,我不得不禁止使用它。当我们停止使用它时,我们的生产力大大提高。

回答by occulus

I tend to avoid storyboards for anything apart from perhaps a quick prototype. If you know you have a very simple app which isn't going to get complicated, and you're the only developer, storyboards might be ok.

除了快速原型之外,我倾向于避免使用故事板。如果您知道自己有一个不会变得复杂的非常简单的应用程序,并且您是唯一的开发人员,那么故事板可能没问题。

Here are a few blog posts that detail some of the pain points when using storyboards:

以下是一些博客文章,详细介绍了使用故事板时的一些痛点:

Both of the above are a bit dated, but I believe the pertinent points still hold true.

以上两者都有些过时,但我相信相关的观点仍然适用。

Note that in theory you need to use a storyboard(s) to get static tables, which can be useful. To get this benefit, you could put only the static tables in storyboard files (note: you can have multiple storyboard files in an app) and use xibs or just code for the rest of the UI.

请注意,理论上您需要使用故事板来获取静态表,这可能很有用。为了获得这个好处,你可以只将静态表放在故事板文件中(注意:你可以在一个应用程序中拥有多个故事板文件)并使用 xibs 或只为 UI 的其余部分编写代码。

回答by Stephen Darlington

I don't think this question is really answerable. There are pros and cons of any technical decision and this one is no different.

我觉得这个问题真的不好回答。任何技术决策都有利有弊,这个也不例外。

Pros:

优点:

  • Visual, so you get a much better idea of what your app will look like more quickly
  • Less code
  • Autolayout canbe easier
  • It's not all-or-nothing. You can build the "base" in Storyboards and finish it off in code
  • 可视化,让您更快地更好地了解您的应用程序的外观
  • 更少的代码
  • 自动布局可以更容易
  • 这不是全有或全无。您可以在 Storyboards 中构建“基础”并在代码中完成它

Cons:

缺点:

  • A big hairball of an XML file makes merge conflicts pretty nasty
  • Less flexibility than code (no inheritance, etc.)
  • If you have lots of screens in your app, using a single storyboard can get pretty difficult unless you have a vast screen!
  • XML 文件的大毛球使合并冲突变得非常讨厌
  • 灵活性不如代码(没有继承等)
  • 如果您的应用程序中有很多屏幕,除非您有一个大屏幕,否则使用单个故事板会变得非常困难!

回答by LE SANG

I think it's not important to use it or not,the most important is how your application is?(quality, beautiful, fast...). StoryBoard is great for beginner to shorten design time and understand. But when to become professional developer, you will love to draw your interface by coding because typing more faster than graphic.

我认为使用与否并不重要,最重要的是您的应用程序如何?(质量,美观,快速......)。StoryBoard 非常适合初学者缩短设计时间和理解。但是当成为专业开发人员时,您会喜欢通过编码来绘制您的界面,因为输入比图形更快。

回答by Dmitry Zheshinsky

It depends only on you. If you developing your application alone, storyboards are very useful. If you work in a team, it's better yo use .xibs because there is less problems with merging them with svn in comparison to storyboards

它只取决于你。如果您单独开发应用程序,故事板非常有用。如果您在团队中工作,最好使用 .xibs,因为与故事板相比,将它们与 svn 合并的问题较少

回答by Anton

Very broad question. There are times when storyboards are great and other times when they are a hassle. Depends on the requirements and compatibility needs of your app.

很广泛的问题。有时故事板很棒,有时却很麻烦。取决于您的应用程序的要求和兼容性需求。

See this answer for a great explanation of when to use storyboards and when to use XIBs:

有关何时使用故事板以及何时使用 XIB 的详细解释,请参阅此答案:

When to use Storyboard and when to use XIBs

何时使用 Storyboard 以及何时使用 XIB