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

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

问题描述

您可以使用设备修饰符(即 ~ipad)在 Info.plist 中提供特定于设备的键,并指定特定于设备的启动图像(iPhone 为 Default.png,而 Default~ipad.png 为例如 iPad).Apple Docs,但他们并没有说这适用于任何其他类型的文件.

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.

我发现(非常偶然)这适用于通过 initWithNibName:bundle: 加载 .xib 文件.例如,我可以拥有 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,在其他设备上加载 MyView.xib.

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

所以,1)这是否在某处记录?我肯定找不到任何 Apple 文档.这肯定比到处检查 UI_USER_INTERFACE_IDIOM() 和硬编码两个不同的笔尖名称更方便,但如果没有记录,我有点不相信它.

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.

而且,2) 有谁知道它在哪个版本的 iOS 上开始工作?我只在 4.2 中尝试过,它在那里工作.设备修饰符一般(即使对于上面列出的文档内容)至少为 4.0.

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.

推荐答案

实际上,它在文档中明确定义,但作为脚注.

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

CocoaNibs

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

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

注意:如果您正在开发一个适用于 iOS 的通用应用程序,您可以使用特定于设备的命名加载正确笔尖的约定底层设备的文件自动地.想要查询更多的信息关于如何命名您的 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."

链接到 Cocoa 概念加载资源

但是,是的,这是 4.0+ 的唯一功能.

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

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

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