iOS:将大型 XIB 重构为几个较小的 XIB 文件以提高速度
在观看一些 WWDC2011 视频
时,有人提到过大的 nib 文件
可能会让您的应用需要一些时间来加载。我的应用程序不一定是这种情况,但我觉得我的笔尖相当大。视频中的建议是将大笔尖分成几个较小的笔尖,以加快加载时间。
也许我遗漏了一些东西,但是我如何将一个大的笔尖分成更小的笔尖呢?我的 UIViewController
在启动时只会加载一个 nib
。还有其他方法可以处理多个文件吗?
When watching some of the WWDC2011 videos
it was mentioned that large nib files
can make your app take some time to load. This isn't necessarily the case with my app, but I feel like my nib
is fairly large. The suggestion on the video was to make that large nib
into a few smaller ones for quick load time.
Maybe I am missing something, but how would I split up a large nib
into smaller ones? My UIViewController
will only load one nib
when it inits. Is there another way to do it will multiple files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所指出的,您可以使用指定的笔尖初始化
UIViewController
来加载其view
属性,而这只是一个文件。但是,您不需要将所有view
属性的子视图打包到同一个 nib 文件中。如果您有一些仅在某些时候可见的子视图,请考虑将它们拆分到自己的 nib 文件中,并使用UINib
按需加载它们。如果您有一组UITableViewCell
子类或用于UIScrollView
内容的图块,您可能希望能够仅加载您实际需要的视图实例,而不是大量的笔尖包含无关的视图(例如,当您只使用其中之一时加载所有表格单元格)。As you noted you can init a
UIViewController
with a specified nib to load itsview
property and that's only a single file. However you need not pack all of yourview
property's subviews into the same nib file. If you have some subviews which are only visible some of the time consider splitting them out into their own nib files and loading them on demand usingUINib
. If you have a set ofUITableViewCell
subclasses or tiles for aUIScrollView
's content you probably want to be able to load only the view instances you actually need and not a massive nib containing extraneous views (e.g. loading all of your table cells when you only use one of them).