NSWindowController 和 NSViewController

发布于 2024-10-18 09:22:34 字数 224 浏览 0 评论 0原文

可能是一个非常简单的问题,但我无法理解它。

我想创建某种向导:一个 NSWindow 显示为另一个 NSWindow 的工作表,并且应该依次显示三个不同的 NSView

我想我应该创建一个自定义的 NSWindowController 和三个 NSViewController 但我不知道如何设置控制器以及如何交换视图。

Probably a pretty simple question, but I can't get my head around it.

I would like to create some sort of wizard: An NSWindow appears as a sheet from another NSWindow and should show three different NSViews one after another.

I think I should create a custom NSWindowController and three NSViewControllers but I don't know how to how to set up the controllers and how to exchange the views.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏天碎花小短裙 2024-10-25 09:22:34

简而言之,您的窗口控制器将实例化三个视图控制器,拥有一个宿主视图,并添加 -[NSView addSubview:] 或删除 -[NSView removeFromSuperView] 视图控制器的视图作为主视图的子视图。根据您构建代码的方式,您还可以使用 -[NSView ReplaceSubview:with:] 将子视图替换为另一个子视图。

Apple 的视图控制器示例代码 具有使用视图控制器进行视图切换的功能。

In a nutshell, your window controller would instantiate the three view controllers, have a host view, and add -[NSView addSubview:] or remove -[NSView removeFromSuperView] the view controllers’ views as subviews of the host view. Depending on how you structure your code, you can also use -[NSView replaceSubview:with:] to replace a subview with another one.

Apple’s View Controller sample code features view switching using view controllers.

做个少女永远怀春 2024-10-25 09:22:34

@Bvarious asnwer 很好,像我这样的人总是需要一段好的代码片段:

appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];
self.masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
[appDelegate.window.contentView replaceSubview:self.view with:self.masterViewController.view];

我创建了 appDelegate 对象,因为它是从 NSViewController 调用的,否则你可以获取视图来自自我。

@Bavarious asnwer is good, folks like me always need a good snippet of code:

appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];
self.masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
[appDelegate.window.contentView replaceSubview:self.view with:self.masterViewController.view];

I create the appDelegate object because it is being called from an NSViewController otherwise you can get the view from self.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文