NSWindowController 和 NSViewController
可能是一个非常简单的问题,但我无法理解它。
我想创建某种向导:一个 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 NSView
s one after another.
I think I should create a custom NSWindowController
and three NSViewController
s but I don't know how to how to set up the controllers and how to exchange the views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,您的窗口控制器将实例化三个视图控制器,拥有一个宿主视图,并添加
-[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.
@Bvarious asnwer 很好,像我这样的人总是需要一段好的代码片段:
我创建了
appDelegate
对象,因为它是从NSViewController
调用的,否则你可以获取视图来自自我。@Bavarious asnwer is good, folks like me always need a good snippet of code:
I create the
appDelegate
object because it is being called from anNSViewController
otherwise you can get the view from self.