ios 哪种方式更有效?故事板还是 XIB?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22524232/
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
Which is more efficient way? StoryBoard or XIB?
提问by Vishal Sharma
My question is slightly different then my title suggest. I have worked with xib. Now i am trying to work with storyboard. My question is if we are navigate through one class from another class, is StoryBoard giving benefit for better memory management. Suppose we have 2 ViewControllers: ViewControllerA and ViewControllerB. We are trying to go through ViewControllerA --> ViewControllerB. Now, in Xib our approach is below;
我的问题与我的标题所暗示的略有不同。我和xib一起工作过。现在我正在尝试使用故事板。我的问题是,如果我们从另一个类中浏览一个类,StoryBoard 是否有利于更好的内存管理。假设我们有 2 个 ViewController:ViewControllerA 和 ViewControllerB。我们正在尝试通过 ViewControllerA --> ViewControllerB。现在,在 Xib 中,我们的方法如下;
ViewControllerB *VCB = [ [ViewControllerB alloc] init];
[self.navigationController pushViewController: VCB Animated: YES];
Where in Story Board,
在故事板中,
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Second"])
{
SecondViewController *objSecond = (SecondViewController*)[segue destinationViewController];
}
}
And Do,
并且做,
[self performSegueWithIdentifier:@"Second" sender:self];
So, My question is We alloc our class in Xib, Where in storyBoard we aren't. So is there any memory allocation advantages in storyboard?
所以,我的问题是我们在 Xib 中分配了我们的班级,而在 storyBoard 中我们不是。那么故事板有什么内存分配优势吗?
回答by Giorgos Ath
My point of view that a professional developer MUST use xibs
, but a hobbyist, new to programming, developer might be helped if he uses storyboard.
我的观点是,专业开发人员MUST use xibs
,但业余爱好者,编程新手,如果使用故事板,开发人员可能会有所帮助。
Storyboard
故事板
After a 3 year project work with a single storyboard I can tell a lot of disadvantages
:
在使用单个故事板进行 3 年的项目工作后,我可以说出lot of disadvantages
:
1) It REALLY gets VERY VERY slow to build even for a very very very little think ( every single view in it must be rebuild ). Also it is very hard to edit even with an iMac with 8 or 16 gb ram if the Storyboard gets bigger. It's even hard to open it.
1)即使是非常非常非常少的思考(其中的每个视图都必须重建),它的构建速度真的非常非常慢。此外,如果 Storyboard 变大,即使使用具有 8 或 16 GB 内存的 iMac 也很难进行编辑。甚至很难打开它。
2) No reusability. There is no way you can import immediately a View/ViewController with its view to another project. It will be connected with other ViewControllers, Views Or Segues and that will make it like a big "don't touch" think.
2) 没有可重用性。您无法立即将带有视图的 View/ViewController 导入另一个项目。它将与其他 ViewControllers、Views 或 Segues 连接,这将使它像一个大的“不要触摸”的想法。
3) there is so much lag when the project gets bigger even for the smallest layout constraint to be added or edited, that you never want to touch it.
3) 即使要添加或编辑最小的布局约束,当项目变大时也会有太多延迟,以至于您永远不想碰它。
4) If you use the cells by automatic cell addition of storyboard, you cannot use the same cell build in two points.
4) 如果您通过情节提要的自动单元格添加使用单元格,则不能在两点使用相同的单元格构建。
Advantage:
优势:
1) Automatic Cells (But this is also a disadvantage because a cell cannot be reused as is to another view)
1)自动单元格(但这也是一个缺点,因为一个单元格不能像另一个视图一样重用)
2) Segues etc would make it easy for someone to understand with a single point of view what is happening.
2) Segues 等将使某人更容易从单一角度理解正在发生的事情。
Xibs:
西布斯:
1) Fully portable.
1)完全便携。
2) Open/Edit/Build SO MUCH MUCH MUCH faster than a storyboard that gets bigger
2) 打开/编辑/构建比故事板变大的速度要快得多
conclusion:
结论:
If you are a hobbyist developer who will make an app for his business for fun, you should use storyboard because it will it easier to understand things. BUT, if you a professional developer, you MUST use xibs for VCs, Cells, etc, Because this is the only way to make them really reusable and portable, in order to gain so much time for the next project, or even when having to make a little change or build the storyboard again.
如果您是一个业余开发者,为了娱乐而为自己的业务制作应用程序,您应该使用故事板,因为它更容易理解事物。但是,如果您是专业开发人员,则必须将 xibs 用于 VC、Cells 等,因为这是使它们真正可重用和可移植的唯一方法,以便为下一个项目或什至不得不花费大量时间做一点改变或重新构建故事板。
Explanation why xibs are more "reusable and portable" for me: Things in programming must be kept in different models, files, entities, modules. One must be as least dependent on another thing as it can get
解释为什么xibs对我来说更“可重用和便携”:编程中的东西必须保存在不同的模型、文件、实体、模块中。一个人必须尽可能不依赖另一件事
回答by codercat
It is not to tell which one is the best. because which one is good to tell based on team requirement.
不是说哪个是最好的。因为根据团队要求来判断哪个好。
If you are a single developer, it is good to use storyboard because it consumes less time. If the team consists of many developers, use xib, otherwise, it is not easy to merge the modules/tasks.
如果你是一个单一的开发者,最好使用 storyboard,因为它消耗的时间更少。如果团队由很多开发人员组成,请使用xib,否则不容易合并模块/任务。
xcode-using-storyboards-and-xibs-versus-creating-views-programmatically
xcode-using-storyboards-and-xibs-versus-creating-views-programmatically
Using XIBs
使用 XIB
Advantages:
好处:
You can quickly put together a UI
Straight-forward implementation for small apps with a minimal number of screens
You can have separate XIBs for different localizations (ie. languages or countries)
Great at laying out elements and visually spotting misalignments. It's easy to make a slight adjustment to the layout
您可以快速组合一个 UI
为具有最少屏幕数量的小型应用程序直接实施
您可以为不同的本地化(即语言或国家/地区)设置单独的 XIB
擅长布置元素和视觉上发现错位。对布局进行微调很容易
Disadvantages:
缺点:
It's difficult to merge conflicts when working in a team environment (hard to diff, merge and read)
Highly dynamic views are impossible to describe as a XIB
Performance wise, it's slower than creating views through code because the xib needs to be read from the disk and analysed/parsed
XIBs lack customizations that you can do in code such as Quartz stuff (drop shadows, round corners)
Harder to debug (i.e. if you forget to make a connection in Interface Builder or make a wrong connection)
在团队环境中工作时很难合并冲突(难以区分、合并和阅读)
高度动态的视图无法描述为 XIB
性能方面,它比通过代码创建视图慢,因为需要从磁盘读取 xib 并进行分析/解析
XIB 缺少您可以在代码中进行的自定义,例如 Quartz 的东西(阴影、圆角)
更难调试(即如果您忘记在 Interface Builder 中建立连接或建立错误的连接)
Storyboards
故事板
Advantages:
好处:
Storyboards are nice for apps with a small to medium amount of screens and the requirements for navigation is relatively straightforward between views
You can mock up the flow of an application without writing much, if any, code
故事板非常适合具有中小型屏幕的应用程序,并且视图之间的导航要求相对简单
您可以模拟应用程序的流程,而无需编写太多代码(如果有的话)
Disadvantages:
缺点:
Storyboards are not compatible with pre-iOS 5 so it makes supporting iOS 4.3 impossible
It's hard to work in parallel in a team environment because everyone's modifying the same file
Along the same lines, merging conflicted storyboards in GIT will be a pain
People have experienced bugs in Xcode with the usage of storyboards (eg. having to frequently flush the DerivedData folder because of inconsistencies)
故事板与 iOS 5 之前的版本不兼容,因此无法支持 iOS 4.3
在团队环境中很难并行工作,因为每个人都在修改同一个文件
同样,在 GIT 中合并冲突的故事板将是一件痛苦的事情
人们在使用故事板时在 Xcode 中遇到过错误(例如,由于不一致而不得不经常刷新 DerivedData 文件夹)
回答by Vineesh TP
Comparing XIB and storyBoard, StoryBoard is fast.
比较XIB和storyBoard,StoryBoard速度很快。
But Actually fast when do the whole project in programatically.
但是当以编程方式完成整个项目时,实际上很快。
in storyboard when we compile all storyBoard is Archive to file. and unArchive then run the application. But, in programatically Classes are allocated at the run time only.
在故事板中,当我们编译所有故事板时,将存档到文件。和 unArchive 然后运行应用程序。但是,以编程方式只在运行时分配类。
Recommended do project using storyboard.
推荐使用故事板做项目。
回答by m-farhan
story board is highly recommended from apple engineers now and highly recommended every thing is central and memory management is done by compiler. how ever pushing a controller is requested by designer in some case and have no issues. but storyboard is recommended and easy to understand view part of MVC
现在苹果工程师强烈推荐故事板,强烈推荐每件事都是中央的,内存管理由编译器完成。在某些情况下,设计师如何要求推送控制器并且没有问题。但推荐使用 storyboard 并且易于理解的 MVC 视图部分
回答by Zubair-Systematix
Using Storyboard would be a better option as far as memory utilisation is concerned although storyboards have other advantages also over xib files, Apple also recommends using storyboard over xib files.
就内存利用率而言,使用 Storyboard 将是一个更好的选择,尽管 Storyboard 与 xib 文件相比还有其他优势,Apple 还建议使用 Storyboard 而不是 xib 文件。