我已经扫描了文档,并在这个主题上录得相当广泛地发现了。

我需要做的是与我的nswindows之一的特定实例进行交互 - 也就是说,通过在Xcode中创建基于文档的应用程序来通过NSDocument系统创建的实例。

所以有办法做到这一点吗?类似[[nsshareddocumentcontroller frontmostwindow] subview:doation],也许是?

有帮助吗?

解决方案

To obtain the frontmost window (aka the main window), use -[NSApplication mainWindow]:

NSWindow *mainWindow = [NSApp mainWindow];

To obtain the window corresponding to a given document:

NSDocument *someDocument; // reference to the document you’re interested in
NSWindow *window = [[[someDocument windowControllers] objectAtIndex:0] window];

NSDocument creates a single window controller to manage the corresponding document window, so -[NSDocument windowControllers] returns an array with a single element corresponding to the window controller. -[NSWindowController window] returns the window managed by that window controller.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top