应该使用iPhone中的NIB或代码创建视图吗? [英] Should views be created using NIBs or code in iPhone?

查看:99
本文介绍了应该使用iPhone中的NIB或代码创建视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Interface Builder设计视图时是否存在任何性能,开发缺陷或优势?

Are there any performance, development drawbacks or advantages when designing views using Interface Builder?

推荐答案

通常你想使用Interface生成器;有几个原因可以让你想通过编程接口来实现这个目的:

Often you want to use Interface Builder; there are several reasons why you would want to do this over programmatic interfaces:


  • 它是更受欢迎的创建用户界面的方式,由于它的简单性和视觉优势是您无法通过简单地使用代码轻松实现的。

  • 它可以帮助您的应用程序符合 iPhone人机界面指南,通过使用标记等,Apple鼓励开发人员遵循,为了保持iPhone应用程序的一致性和可用性。

  • it is the more accepted way of creating user interfaces, due to its simplicity and visual advantages that you can't achieve as easily by simply using code.
  • it helps your applications to conform to the iPhone Human Interface Guidelines, through the use of the markers etc, which Apple encourage developers to follow, in order to maintain consistency and usability across iPhone applications.

尽管如此,编程接口有时比使用接口更有利的主要原因Builder适用于需要多次创建的界面元素 - 例如,创建 n UIImageView s - 基于a无法复制的变量在Interface Builder中。程序化接口允许这种灵活性,在这种情况下通常更有效。

Despite this, the main reason why programmatic interfaces are sometimes more favourable over using Interface Builder is for interface elements that need to be created several times - for example, creating n UIImageViews - based on a variable that cannot be replicated in Interface Builder. Programmatic interfaces allow for this flexibility and are usually more efficient in this case.

请注意,NIB / XIB也占用内存,如果所有接口都放在您的主要NIB文件,它不仅会增加您的应用程序的内存使用量(对于可能无法立即需要的资源),但会增加加载时间。尽管如此,这个问题的正常解决方法不是使用编程接口,而是将不同的接口元素组放在不同的NIB文件中,将所需的接口放在主NIB文件中,该文件在应用程序启动时加载和其他NIB文件中的其他接口元素组在需要时加载。

Note that NIBs/XIBs do also take up memory, and if all of your interfaces are placed in your main NIB file, it will not only increase memory usage by your application (for resources which may not be needed instantly anyway) but it will increase loading time. That being said, however, the normal workaround to this problem is not to use programmatic interfaces, but to place different groups of interface elements in different NIB files, placing the immediately required interfaces in the main NIB file, which gets loaded when the application starts, and other groups of interface elements in other NIB files which get loaded when required.

简而言之,一般的方法是使用Interface Builder,除非你在需要创建可变数量的元素,这些元素在Interface Builder中无法轻易处理。

In short, the general way to go is to use Interface Builder, except for when you need to create a variable amount of elements that cannot easily be dealt with in Interface Builder.

这篇关于应该使用iPhone中的NIB或代码创建视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆