NSView,NSViewController和MainMenu.xib如何整合在一起? [英] How exactly does an NSView, an NSViewController, and MainMenu.xib fit together?

查看:693
本文介绍了NSView,NSViewController和MainMenu.xib如何整合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要切换到追逐:我的应用程序已经增长了很多,现在我认为是时候做一些整理了。我想把我的MainMenu.xib文件中的一些视图分成他们自己的Nib文件。引发我的部分是整个界面生成器+我的代码的东西。这是我到目前为止所做的:

I'm going to cut right to the chase: my application has grown quite a bit, and now I think it's time for me to do some tidying up. I want to separate some of my views from my MainMenu.xib file into their own Nib file. The part that's tripping me up is the whole "Interface Builder + My Code" thing. Here's what I've done so far:


  1. 我添加了一个视图控制器代理对象:

  1. I've added a view controller proxy object:

身份检查器中,我已将我的视图控制器的类名添加到自定义类字段。

In the Identity inspector, I've added my view controller's class name to the Custom Class field.

属性检查器中, ve输入了我想要加载的Nib的名称。

In the Attributes inspector, I've entered the name of the Nib I want to load up.

我已将视图控制器对象的视图插座连接到MainMenu.xib中的现有视图。

I've connected the view controller object's view outlet to an existing view in MainMenu.xib.

最后,我打Cmd + R,不存在。

[在此处插入FFFFUUUUU meme的图片。]

Finally, I hit Cmd+R, and my view isn't there.
[Insert image of FFFFUUUUU meme here.]

我错过了?我在过去两个星期一直盯着我的Mac,所以如果我完全留下了东西,我不会感到惊讶。如果有人看到我的n00b的方式,并愿意指出我的方向正确,我会非常感激。感谢。

What am I missing? I've been staring at my Mac day-in and day-out for the last two weeks, so I wouldn't be surprised if I've completely left something out. If anyone sees my n00b ways and would be willing to point me in the right direction, I'd be really grateful. Thanks.

推荐答案

你差不多了。

GitHub上的演示项目

最后,你需要实际添加视图到窗口。在 AppDelegate
或您认为合适的地方执行此操作。

Finally, you need to actually add the view to the window. Do this in your AppDelegate, or wherever you think is suitable.

- (void)awakeFromNib {
    [self.window.contentView addSubview:self.customViewController.view];
    [self.customViewController.view setFrame:[self.window.contentView bounds]];
}

或者,您首先需要为您的视图控制器创建一个插座: / p>

Or course, you first need to make an outlet for your view controller:

@property (assign) IBOutlet ITCustomViewController *customViewController;

这篇关于NSView,NSViewController和MainMenu.xib如何整合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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