العمل مع ضوابط النافذة الأمامية في تطبيق يستند إلى المستند؟
-
15-11-2019 - |
سؤال
لقد قمت بمسح الضوابط و GoogleLed بشكل حد بعيد ولم يتم العثور على شيء في هذا الموضوع.
ما الذي حذرته للقيام به هو التفاعل مع مثيل محدد لأحد NSWindows - أي واحدة تم إنشاؤها من خلال نظام NSDocument وضعت في مكانه عن طريق إنشاء تطبيق يستند إلى المستند في Xcode.
هل هناك طريقة للقيام بذلك؟شيء من هذا القبيل [[nssharedDocumentcontroller frontwindwindow] الفرعية الفرعية: المقدمة]، ربما؟
المحلول
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.