0

是否有可能以某种方式为不同的 OS X 版本提供不同的 nib 文件?因为例如 10.6 没有自动布局功能,而在 10.7 和 10.8 上它是一个很棒的功能。因此,如果可能的话,我可以为 10.6 创建一个笔尖,为 10.7 和 10.8 创建另一个笔尖。

4

2 回答 2

1

当然。只需创建不同的 NIB 文件,例如在这些文件的名称末尾添加版本,然后在运行时找出当前系统正在运行的 OS X 版本,并以编程方式为 OS X 版本加载正确的库。

不过,为您的应用程序的“主要”NIB 这样做会相当困难(有可能,我以前做过,但我不推荐它)。只需使您的主 NIB 10.6 兼容,并且只将主菜单以及应用程序委托放入其中(如果您希望它由 NIB 文件创建而不是通过编程方式创建)。将所有窗口、视图和其他 UI 元素放入单独的 NIB 文件中,然后在您的应用程序委托中,以编程方式在回调中加载 NIB 文件,例如applicationDidFinishLaunching:

只需查看Apple 的 NIB 文件文档,然后搜索“以编程方式加载 Nib 文件”。有一些有用的链接指向所需的方法,以及一些简单常见情况的示例代码。

于 2012-10-18T15:36:24.500 回答
0

Yes, just supply different NIB filenames when loading them. The one place where you can't do this is the application NIB, but it should be free of UI elements beside the menu bar, so just leave it springs-and-struts (ie not autolayout).

This may involve overriding makeWindowControllers or windowNibName on NSDocument, for example, in order to work on the NIB filename. See the documentation for more information about solving this for a particular class - it is definitely doable.

于 2012-10-18T15:24:58.887 回答