负载可可碎粒 [英] load nibs in cocoa

查看:138
本文介绍了负载可可碎粒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在另一个窗口中加载nib?

How can I load a nib inside of another window?

我试过initWithWindowName,

I tried initWithWindowName,

if (mmController == NULL)
    mmController = [[mainMenu alloc] initWithWindowNibName:@"mainMenu"];
[mmController showWindow:self];

但会打开一个新窗口。

我也尝试过loadNibNamed

I also tried loadNibNamed

[NSBundle loadNibNamed:@"mainGame" owner:self];

并成功,但是当我尝试使用相同的方法返回主菜单时,

and it succeeded, but when I try to use the same method to get back to the main menu,

[NSBundle loadNibNamed:@"mainMenu" owner:self];

它不工作。它什么都不做...
任何想法?

it doesn't work. It does nothing at all... Any ideas?

推荐答案


我试过initWithWindowName ,

I tried initWithWindowName,

您的意思是initWithWindow¹Nib²Name³:,其名称为包含窗口(1)的nib(2)。

You mean initWithWindow¹Nib²Name³:, which takes the name (3) of a nib (2) containing a window (1).


if (mmController == NULL)


这应该是 nil ,而不是 NULL ,因为您正在比较一个Objective-C对象指针。

This should be nil, not NULL, since you are comparing an Objective-C object pointer.


    mmController = [[mainMenu alloc] initWithWindowNibName:@"mainMenu"];


什么是 mainMenu 这里?它必须是一个类,但它是什么子类?

What is mainMenu here? It must be a class, but what is it a subclass of?


[mmController showWindow:self];


从此邮件和上一封邮件, code> mainMenu 是NSWindowController的子类。

From this message and the previous message, I'm guessing mainMenu is a subclass of NSWindowController.

不需要猜测。你应该明确地命名你的类,所以任何人都可以告诉这个类是什么,它的实例只是类名。

Guessing should not be required. You should name your classes specifically, so that anybody can tell what the class is and its instances are merely by the class name.

简洁是一种美德,但如果你需要去长,去长。我们有名称完成的现代工具。标签键可以消除缩写名称的唯一优点。

Brevity is a virtue, but if you need to go long, go long. We've got modern tools with name completion. The tab key can eliminate the sole advantage of an abbreviated name.


但它打开一个新窗口。

but it opens a new window.

是的。你通过从一个nib加载一个窗口,然后你告诉窗口控制器来显示那个窗口。显示新窗口是预期结果。

Yes. You created a window by loading it from a nib, and then you told the window controller to show that window. Showing a new window is the expected result.


我也尝试过loadNibNamed

I also tried loadNibNamed

[NSBundle loadNibNamed:@"mainGame" owner:self];

并成功,但是当我尝试使用相同的方法返回主菜单时,

and it succeeded, but when I try to use the same method to get back to the main menu,

没有回头。加载nib只是通过从存档加载对象来创建对象。

There is no "get back". Loading a nib is simply creating objects by loading them from an archive. You can load the same nib multiple times, and loading a nib does not somehow undo the results of loading a previous nib.

您可能想要读取资源编程指南,其中涵盖了笔尖以及图像和声音文件,以及 Bundle编程指南

You may want to read the Resource Programming Guide, which covers nibs as well as image and sound files, and the Bundle Programming Guide.

如果您想要隐藏从 mainGame nib中加载的窗口,请这样做。在AppKit中的术语是排序(而不是排序,其中排前排序返回是特定的做法)。

If you want to hide the window you loaded from the mainGame nib, do that. The term for this in AppKit is "ordering out" (as opposed to "ordering in", which "ordering front" and "ordering back" are specific ways of doing).


[NSBundle loadNibNamed:@"mainMenu" owner:self];

它不工作。它什么也不做...

it doesn't work. It does nothing at all...

您是否正在尝试加载项目附带的MainMenu nib?如果是这样,请确保您的案例是正确的 - 你不想让你的应用程序破坏从运行它的区分大小写的卷,或者你不想破坏的人谁使用默认不区分大小写文件系统。

Are you trying to load the MainMenu nib that came with your project? If so, make sure you get the case right—you don't want your app to be broken for people who run it from a case-sensitive volume, nor do you want it to be broken for people who use the default case-insensitive file-system.

如果这不是你想做的,那么它不清楚你在做什么。 MainMenu通常是包含主菜单的nib(菜单栏的内容);命名任何其他nibmainMenu或任何类似的东西将导致最好的混乱和最坏的问题。如果这应该是一些其他的笔尖,你应该给它一个不同的名字。

If that's not what you're trying to do, then it isn't clear what you are trying to do. MainMenu is normally the nib containing the main menu (the contents of the menu bar); naming any other nib "mainMenu" or anything like that is going to cause confusion at best and problems at worst. If this is supposed to be some other nib, you should give it a different name.

不管怎样,这不是你需要做的。如果要隐藏从 mainGame 加载的窗口,则需要隐藏该窗口,而不是加载不同的nib。

Either way, this is not what you need to do. If you want to hide the window you loaded from mainGame, then you need to hide that window, not load a different nib.

此外,一旦窗口加载,不要再次加载(除非你关闭和释放它)。一旦你加载它,你可以简单地订购它。很可能,你会想要制作它的键并将其排在前面

Moreover, once the window is loaded, do not load it again (unless you close and release it). Once you have loaded it, you can simply order it back in. Most probably, you will want to both make it key and order it front.

在Mac上,您不限于一次一个窗口;的确,你的应用程序有多个窗口(至少三个),无论你做什么。这些API是建立在显示多个窗口的能力之上的。

On the Mac, you are not limited to one window at a time; indeed, your app has multiple windows (at least three), no matter what you do. The APIs are built around your ability to show multiple windows.

请参阅窗口编程指南了解更多信息。


如何将nib加载到另一个窗口?

How can I load a nib inside of another window?

由于Justin Meiners已经告诉你,你可能想要NSViewController,虽然你可以不用,该视图直接使用 loadNibNamed:

As Justin Meiners already told you, you may want NSViewController for that, although you can go without and just load the nib containing the view directly using loadNibNamed:.

警告,NSViewController不像Cocoa Touch的UIViewController 。

Be warned that NSViewController is not nearly as powerful/featureful as Cocoa Touch's UIViewController.

您需要阅读查看编程指南

这篇关于负载可可碎粒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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