Trabalhando com os controles do frontmost window em um aplicativo baseado em documentos?
-
15-11-2019 - |
Pergunta
Eu digitalizei a documentação e pesquisei bastante extensivamente e não encontrei nada sobre este assunto.
O que estou precisando fazer é interagir com uma instância específica de um dos meus nws - isto é, um criado através do sistema NSDocument colocado ao criar um aplicativo baseado em documentos no Xcode.
Então, há uma maneira de fazer isso?Algo como [[NSSharedDocumentController FrontmostWindow] subview: Doação], talvez?
Solução
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.