将 NSView 分配给 NIB 中窗口的 contentView

发布于 2024-12-22 20:21:18 字数 665 浏览 4 评论 0原文

我正在做一个以编程方式分配视图的练习,但作者说:“我们可以在 IB 中执行此操作,但让我们用代码执行此操作”。

这是设置。

1)2个nib文件,一个“MainMenu”,另一个“ActivityView”nib。在本例中,“MainMenu”笔尖包含窗口和内容视图。 “ActivityView”包含一个视图,其文件的所有者是一个子类 NSViewController,它在“MainMenu”笔尖中实例化。 另一件事是 AppDelegate 包含 MainMenu nib 文件中“ActivityView”对象的 IBOutlet。 因此,以编程方式,在“applicationDidFinishLaunching”(AppDelegate 的)中,使用且有效的代码是:

    self.window.contentView=ac.view // where ac is an NSViewController Subclass

我想了解如何在 IB 中执行此操作,但一直无法执行此操作。最接近的是从第二个笔尖复制并粘贴视图的建议(可行),但看起来并不优雅,或者也许这就是完成的方式。将MainMenu nib 中的ActivityController 的视图出口(即ActivityView 的nib 的所有者)连接到窗口的视图是行不通的。我很可能没有问正确的问题,所以希望能对我所缺少的问题有一些见解。

I am doing an exercise that assigns a view programmatically, but in which the author says, "We could do this in IB, but let's do it in code".

Here is the setUp.

1) 2 nib files, one "MainMenu" , the other an "ActivityView" nib. In this case, the "MainMenu" nib contains the Window and the contentView. The "ActivityView" contains a view, whose file's Owner is a subclassed NSViewController, which is instantiated in the "MainMenu" nib.
The other thing is that the AppDelegate contains an IBOutlet to the "ActivityView" object in the MainMenu nib file.
So, programmatically, in the "applicationDidFinishLaunching" (of the AppDelegate), the code that is used, and works is:

    self.window.contentView=ac.view // where ac is an NSViewController Subclass

I would like to understand how to do this in the IB, but have been unable to do so. The closest was a suggestion to copy and paste the view from the 2nd nib, ( which works) but does not seem elegant, or perhaps this is the way it is done. Connecting the view outlet of the ActivityController ( i.e. the owner of the ActivityView's nib) in the MainMenu nib to the view of the window, does not work. There is a good chance I am not asking the correct question, so would appreciate some insights into what the issue is that I am missing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文