iOS:使用设备修饰符加载xib文件? [英] iOS: Using device modifiers for loading xib files?

查看:123
本文介绍了iOS:使用设备修饰符加载xib文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用设备修改器(即〜ipad)在Info.plist中提供特定于设备的键,并指定特定于设备的启动图像(Default.png为iPhone,Default〜ipad.png为iPad,例如)。在 Apple文档中特别提到了这两点,但是他们不会说这将适用于任何其他类型的文件。

You can use a device modifier (i.e., ~ipad) to provide a device-specific key in Info.plist, and to specify a device-specific launch image (Default.png for iPhone, and Default~ipad.png for iPad, for example). Those two things are specifically mentioned in Apple Docs, but they don't say that this will work for any other kinds of files.

我发现(很意外),这适用于通过加载.xib文件 initWithNibName:bundle:。例如,我可以有MyView.xib和MyView〜ipad.xib,并且这个代码:

I've discovered (quite by accident) that this works for loading .xib files via initWithNibName:bundle:. So for example, I can have MyView.xib and MyView~ipad.xib, and this code:

MyViewController *viewController = [[MyViewController alloc] 
                                     initWithNibName:@"MyView" bundle:nil];

...将在iPad上完全加载MyView〜ipad.xib,设备。

... will totally load MyView~ipad.xib on an iPad, and MyView.xib on other devices.

所以,1)这是记录在某处吗?我肯定找不到任何任何苹果文档。它确实比检查UI_USER_INTERFACE_IDIOM()和硬编码两个不同的nib名称无处不在,但我不相信它,如果它没有记录。

So, 1) Is this documented somewhere? I sure couldn't find it any any Apple docs. It's sure handier than checking UI_USER_INTERFACE_IDIOM() and hardcoding two different nib names everywhere, but I kinda don't trust it if it isn't documented.

有人知道什么版本的iOS这开始工作吗?我只试过它在4.2,它的工作原理。

And, 2) Does anyone know what version of iOS this started working in? I've only tried it in 4.2, and it works there. Device modifiers in general (even for the documented things listed above) are 4.0 minimum.

推荐答案

实际上,它是明确定义在docs,但作为脚注。

Actually, it is explicitly defined in the docs, but as a footnote.

CocoaNibs

在载入NIB底部的注释中文件使用NSBundle:

In the note at the bottom of "Loading NIB files using NSBundle":


注意:如果你正在为iOS开发一个
Universal应用程序,设备特定命名
约定自动为底层设备
加载正确的nib
文件。有关如何命名nib文件的更多信息,请参阅
iOS支持特定于设备的
资源。

Note: If you are developing a Universal application for iOS, you can use the device-specific naming conventions to load the correct nib file for the underlying device automatically. For more information about how to name your nib files, see "iOS Supports Device-Specific Resources."

其中链接到可可概念加载资源

但是,这是一个仅限4.0+的功能。

However, yes, this is a 4.0+ only feature.

这篇关于iOS:使用设备修饰符加载xib文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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