Mac OS X Cocoa 单窗口应用程序架构
我无法理解如何以最佳方式设计应用程序,以使单窗口应用程序在 Mac OS X 中工作。我更喜欢单个文档 - 单窗口应用程序(我没有编写实用程序应用程序),但不清楚在哪里我应该初始化窗口内容吗?
在 iOS 上,我应该使用根视图控制器的 -[UIViewController viewDidLoad]
或 -[UIViewController viewWillAppear:]
方法来实现此目的。
您能给我建议任何教程或解释如何处理 NSDocument - NSDocumentController - NSWindowController - NSViewController 类吗?
感谢您的回答。 :-)
I cannot understand how to design an application in optimal way for a single window application to work in Mac OS X. I would prefer a single document - single window application (I'm not coding a utility application), but it is not clear where should I initialize a window content.
On iOS I should use -[UIViewController viewDidLoad]
or -[UIViewController viewWillAppear:]
method of a root view controller for that purpose.
Could you please advice me any tutorial or explain how to deal with NSDocument - NSDocumentController - NSWindowController - NSViewController classes?
Thanks for your answers. :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将窗口逻辑放入 AppDelegate 中,但我不鼓励这样做。我建议您使用自己的单独的 NSWindowController 子类来控制窗口,即使对于单窗口应用程序也是如此。这是一次非常美好的分离。
我不明白为什么有人想要将 NSDocumentController 用于单窗口应用程序。
NSViewController
旨在控制您的自定义视图。它通常不会在普通的简单 Mac 应用程序中使用,除非您有一些想要专门控制的自定义视图。因此,在您的 AppDelegate 中,例如
applicationDidFinishLaunching:
,您将分配并初始化窗口控制器并显示窗口。Hillegass 的“Cocoa Programming for Mac OS X”中有一个很好的章节介绍了如何使用窗口控制器。当然,苹果的文档也有一些相关材料。
You could put your window logic into your AppDelegate, but I discourage it. I recommend doing your own separate
NSWindowController
subclass to control the window, even for a single-window app. It's a very nice separation.I don't see why one would want to use
NSDocumentController
for a single-window app.NSViewController
is meant to control your custom views. It's usually not used in the average simple Mac app, unless you have some custom views you want to control specially.So, in your AppDelegate's, say,
applicationDidFinishLaunching:
, you would allocate and initialize the window controller and show the window.There is a good chapter in "Cocoa Programming for Mac OS X" by Hillegass on how to work with window controllers. Apple's docs also have some material on it, of course.