一个XIB内的多个视图 - iPhone SDK [英] Multiple Views within one XIB - iPhone SDK

查看:109
本文介绍了一个XIB内的多个视图 - iPhone SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在花时间学习如何使用iPhone SDK。我读过开始iPhone开发:探索iPhone SDK 从封面到封面,我从未在一个XIB中看到多个视图的示例。

I have been spending time learning how to use the iPhone SDK. I've read "Beginning iPhone Development: Exploring the iPhone SDK" from cover to cover and I've never seen an example of multiple views within one XIB.

为了说明我的意思,这里是一个XIB的屏幕截图,其中包含我所指的简单配置:

To illustrate what I mean, here is a screen shot of a XIB with the simple configuration of what I'm referring to:

alt text http:/ /theopensourceu.com/wp-content/uploads/2009/04/one-xib-multiple-views.png

我认为必须有一个非常具体的原因,我从来没有见过这个。在Apple的示例和我迄今为止的所有读数中,多个XIB仅使用一个视图(有时是导航控制器或标签栏控制器等)。这是什么原因?我应该避免XIB内的多个视图吗?这两种方法有哪些优点或缺点?

I figure that there has to be a very specific reason that I've never seen this. In Apple's examples and in all of my readings thus far, multiple XIBs are used with only a single 'view' (and sometimes the Navigation Controller or a Tab Bar Controller, etc). What is the reason for this? Should I avoid multiple views inside a XIB? What are the advantages or disadvantages to to either method?

提前谢谢

推荐答案

这是内存优化的问题和加载时间。如果您将所有视图放在一个XIB中,那么当您的应用程序启动时,它必须将整个XIB加载到内存中并构建所有控件的所有对象,这需要花费非常少的时间。

It's a question of memory optimization and loading times. If you put all your views in one XIB, then when your application launches, it has to load the entire XIB into memory and construct all of the objects for all of the controls, and this takes a non-trivial amount of time.

如果您将视图分成单独的XIB,那么您的应用程序将启动得更快,因为只会加载包含初始视图的XIB,并且它也会使用更少的记忆起初。然后,当视图更改时,您可以懒惰地加载包含新视图的XIB。这在第一次打开视图时会产生轻微的故障。如果你真的试图优化内存使用,你也可以在切换视图时卸载前一个视图,但我不建议这样做,因为这会在每次切换视图时出现问题,而是只是你第一次切换到任何给定的视图。

If instead you separate your views into separate XIBs, then your app will start up much faster, because only the XIB containing the initial view will be loaded, and it will also use less memory at first. Then, when the view changes, you can load the XIB containing the new view lazily. This will incur a minor hitch when opening a view for the first time. If you're really trying to optimize memory use, you can also unload the previous view when switching views, but I wouldn't recommend this, as this will incur a hitch every time you switch views, instead of just the first time you switch to any given view.

这篇关于一个XIB内的多个视图 - iPhone SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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