开发者

Working with the frontmost window's controls in a document-based app?

开发者 https://www.devze.com 2023-02-10 23:51 出处:网络
I\'ve scanned the documentation and googled fairly extensively and found nothing on this subject. What I\'m needing to do is interact with a specific instance of one of my NSWindows - that is, one cr

I've scanned the documentation and googled fairly extensively and found nothing on this subject.

What I'm needing to do is interact with a specific instance of one of my NSWindows - that is, one created through the开发者_Go百科 NSDocument system put in place by creating a document-based application in Xcode.

So is there a way to do this? Something like [[NSSharedDocumentController frontmostWindow] subView: doAction], perhaps?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号