How to close the front application window - objective-c

I want to close the front window of my application. How is that done?

Try [myWindow close] or [myWindow performClose:nil].
Use [NSApplication keyWindow] to get the key window if needed. If you want just the front-most one, grab the first one from [NSApplication orderedWindows].

Related

Show all NSWindows

Pretty simple idea here, I want to show all the NSWindows in an app. The idea being that there are two windows in the app, one his hidden the other is vissable. I want to show all the windows in the app and then hide one. I can hide the window I want to hide but I cant show the windows because I am unable to obtain a reference to it. is there anyway of getting a list of all the nswindows in the app then iterating through it and hiding them or something similar, I can use [NSApp windows] however trying to use
NSArray *windowArray = [NSApp windows];
[windowArray[0] makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
does not work, nor does:
NSArray *windowArray = [NSApp windows];
NSWindow *tempWindow = windowArray[0];
[tempWindow makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
any suggestions?
Well in hindsight I've been a bit stupid. I had two seep rate controller objects each running one window. One was hardly doing anything as the view inside it was being handled by a different object so I just removed that one and made the first controller object take care of both windows. Problem solved.

Cocoa/ How do I get a reference to current window's contentViewController in app delegate?

How do I get a reference to current window's contentViewController in app delegate?
There could be two possible definitions for what you mean by "Current" window
The key window is the window that receives the key events (keep in mind this could be a panel within a window), while the main window is the current parent window that is open, but doesn't necessarily receive the key events.
You can access either of these windows with these lines, and subsequently grab a reference to their contentViews:
[[[NSApplication sharedApplication] mainWindow] contentView];
[[[NSApplication sharedApplication] keyWindow] contentView];

How to close current window after a new window showed

In current NSWindowController, add a child window (mainViewController.window),then close current window,BUT when the method [self.window close] is called, the App terminated(not crash,because I can get the log message form method windowWillClose);
[self.window addChildWindow:mainViewController.window ordered:NSWindowAbove];
[self.window close];
What I want is : close current window when a new window showed.Is my way wrong?
=================================== UPDATE ====================================
Thanks #rdelmar, my mistake ,the App is not terminated,just all windows closed .
[self.window orderFront:mainViewController.window];
[self.window close];
If you want to close one window when you open another, then you shouldn't make that second window a child of the first. When you close a child window's parent window, the child will close also. You can just create a new window in code and then use orderFront or makeKeyAndOrderFront: to bring it on screen, then close your other window. You could also add another window in IB, and uncheck Visible At Launch so it will only show up when you call one of the methods I mentioned above.

Cocoa topmost window

How could I get one of my Cocoa application windows to get (and maintain) on top all desktop windows while my apllication stay running?
Have a look at NSWindow's -setLevel: method:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWindow/setLevel:
You have to make the window key and order it to front. Use this
[[myWindowController window] makeKeyAndOrderFront:self];

Is it possible to bring window to front without taking focus?

I am working on an application for my personal usage that will remind me of stuff at regular intervals and/or will require text entry. Hence this popup window has an NSTextField.
If the window pop's up when I am in the middle of typing, my typing transfers to the popup window which is very annoying! Is there any way to stop this, currently I am using:
[NSApp activateIgnoringOtherApps:YES];
[hudWindow makeKeyAndOrderFront:nil];
I have also tried:
[NSApp activateIgnoringOtherApps:YES];
[hudWindow orderFrontRegardless];
Is there any other way to do it?
[hudWindow orderFront: nil];
Moves the window to the front of its level in the screen list, without changing either the key window or the main window.
Did you try using setLevel:? Setting it to one of the higher levels should do the trick.
like
[hudWindow
setLevel:NSFloatingWindowLevel];