哪种方式更有效? StoryBoard还是XIB?

时间:2022-10-15 04:18:07

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个ViewControllers: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中我们不是。故事板中是否有任何内存分配优势?

5 个解决方案

#1


33  

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.

如果您是单个开发人员,最好使用故事板,因为它消耗的时间更少。如果团队由许多开发人员组成,请使用xib,否则,合并模块/任务并不容易。

xcode-using-storyboards-and-xibs-versus-creating-views-programmatically

xcode的-使用-故事板 - 和 - xibs抗创建的视图,编程

Using XIBs

Advantages:

优点:

  • You can quickly put together a UI

    您可以快速组合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)

    您可以为不同的本地化(即语言或国家/地区)提供单独的XIB

  • Great at laying out elements and visually spotting misalignments. It’s easy to make a slight adjustment to the layout

    擅长布置元素并在视觉上发现错位。轻松调整布局很容易

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

    高动态视图无法描述为XIB

  • Performance wise, it’s slower than creating views through code because the xib needs to be read from the disk and analysed/parsed

    性能方面,它比通过代码创建视图慢,因为需要从磁盘读取xib并进行分析/解析

  • XIBs lack customizations that you can do in code such as Quartz stuff (drop shadows, round corners)

    XIB缺少您可以在代码中进行的自定义,例如Quartz的东西(阴影,圆角)

  • Harder to debug (i.e. if you forget to make a connection in Interface Builder or make a wrong connection)

    更难调试(即如果您忘记在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

    故事板与iOS 5之前的版本不兼容,因此无法支持iOS 4.3

  • 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

    同样,在GIT中合并冲突的故事板将是一件痛苦的事

  • People have experienced bugs in Xcode with the usage of storyboards (eg. having to frequently flush the DerivedData folder because of inconsistencies)

    人们在使用故事板时遇到了Xcode中的错误(例如由于不一致而不得不经常刷新DerivedData文件夹)

#2


36  

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.

我的观点是,专业开发人员必须使用xibs,但是如果他使用故事板,那么对于编程,开发人员来说,开发人员可能会有所帮助。

Storyboard

故事板

After a 3 year project work with a single storyboard I can tell a lot of disadvantages:

使用单个故事板进行了3年的项目工作后,我可以说出许多缺点:

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)即使是非常非常小的想法,它的构建也非常非常缓慢(其中的每个视图都必须重建)。如果故事板变大,即使使用带有8或16 GB RAM的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:

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,Cell等,因为这是使它们真正可重用和便携的唯一方法,以便为下一个项目获得这么多时间,或者甚至不得不做一点改变或再次构建故事板。

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

解释为什么xib对我来说更“可重用和可移植”:编程中的东西必须保存在不同的模型,文件,实体,模块中。一个人必须至少依赖于另一件事,因为它可以得到

#3


6  

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.

在故事板中,当我们编译所有storyBoard是归档到文件。然后unArchive运行应用程序。但是,在编程中,类仅在运行时分配。

#4


0  

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

故事板现在是苹果工程师强烈推荐的,强烈建议每件事都是中心的,内存管理由编译器完成。在某些情况下,如何设计师要求推动控制器并且没有问题。但故事板是推荐的,易于理解的视图部分MVC

#5


0  

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.

尽管故事板还具有xib文件的其他优点,但使用Storyboard对内存利用率来说是一个更好的选择,Apple也建议在xib文件上使用storyboard。

#1


33  

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.

如果您是单个开发人员,最好使用故事板,因为它消耗的时间更少。如果团队由许多开发人员组成,请使用xib,否则,合并模块/任务并不容易。

xcode-using-storyboards-and-xibs-versus-creating-views-programmatically

xcode的-使用-故事板 - 和 - xibs抗创建的视图,编程

Using XIBs

Advantages:

优点:

  • You can quickly put together a UI

    您可以快速组合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)

    您可以为不同的本地化(即语言或国家/地区)提供单独的XIB

  • Great at laying out elements and visually spotting misalignments. It’s easy to make a slight adjustment to the layout

    擅长布置元素并在视觉上发现错位。轻松调整布局很容易

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

    高动态视图无法描述为XIB

  • Performance wise, it’s slower than creating views through code because the xib needs to be read from the disk and analysed/parsed

    性能方面,它比通过代码创建视图慢,因为需要从磁盘读取xib并进行分析/解析

  • XIBs lack customizations that you can do in code such as Quartz stuff (drop shadows, round corners)

    XIB缺少您可以在代码中进行的自定义,例如Quartz的东西(阴影,圆角)

  • Harder to debug (i.e. if you forget to make a connection in Interface Builder or make a wrong connection)

    更难调试(即如果您忘记在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

    故事板与iOS 5之前的版本不兼容,因此无法支持iOS 4.3

  • 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

    同样,在GIT中合并冲突的故事板将是一件痛苦的事

  • People have experienced bugs in Xcode with the usage of storyboards (eg. having to frequently flush the DerivedData folder because of inconsistencies)

    人们在使用故事板时遇到了Xcode中的错误(例如由于不一致而不得不经常刷新DerivedData文件夹)

#2


36  

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.

我的观点是,专业开发人员必须使用xibs,但是如果他使用故事板,那么对于编程,开发人员来说,开发人员可能会有所帮助。

Storyboard

故事板

After a 3 year project work with a single storyboard I can tell a lot of disadvantages:

使用单个故事板进行了3年的项目工作后,我可以说出许多缺点:

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)即使是非常非常小的想法,它的构建也非常非常缓慢(其中的每个视图都必须重建)。如果故事板变大,即使使用带有8或16 GB RAM的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:

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,Cell等,因为这是使它们真正可重用和便携的唯一方法,以便为下一个项目获得这么多时间,或者甚至不得不做一点改变或再次构建故事板。

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

解释为什么xib对我来说更“可重用和可移植”:编程中的东西必须保存在不同的模型,文件,实体,模块中。一个人必须至少依赖于另一件事,因为它可以得到

#3


6  

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.

在故事板中,当我们编译所有storyBoard是归档到文件。然后unArchive运行应用程序。但是,在编程中,类仅在运行时分配。

#4


0  

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

故事板现在是苹果工程师强烈推荐的,强烈建议每件事都是中心的,内存管理由编译器完成。在某些情况下,如何设计师要求推动控制器并且没有问题。但故事板是推荐的,易于理解的视图部分MVC

#5


0  

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.

尽管故事板还具有xib文件的其他优点,但使用Storyboard对内存利用率来说是一个更好的选择,Apple也建议在xib文件上使用storyboard。