Launch method when window (and its views) appear in Cocoa - objective-c

I have a multi Window (A,B,C) application. User can close Window A(transparent and buttonless) by pressing a specific button on interface, at some point he can reopen it by click another button.
It works great, by i need reset some values when window is opened again.
I know that awakeFromNib is called from window and from view but only once, it doesn't be call again at window reopen. Is there a method that Window (and Views ?) call when window reopen ? something like viewWDidAppear for IOS ?

You could register for the UIWindowDidBecomeVisibleNotification for that.

Related

Cocoa - How to bring particular window to come in foreground from StatusMenu

I am working on an Mac Application. I have set Application is agent (UIElement) = YES in plist, and App have a Window (lets say Popup Window) that acts as custom PopOver for StatusMenu. One more window is there (lets say Window B) that should opened on selecting a Link from StatusMenu that i have made, but Problems that I am facing are as follow:
On Application launch, When I opens status Menu It also showing Window B, that actually should not be Shown. Window B is allocated and initialised in Application Delegate.
Another Issue is When Window B is made Visible by Selecting it from StatusMenu. It appears well, Now i switch to another application so Its window is sent to background that is fine, but Whenever I click on Status Menu, It automatically comes in Front. Ideally It should only open Popup window.
Window B is opening because you might be forgot to un-check "Visible At Launch" window property in attribute inspector of interface builder
2nd issue you can resolve by activateIgnoringOtherApps set to YES before calling your window
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[windowB showWindow:nil];

How to wait for window to close inside a framework?

I have to create a function into a framework which opens a window with a radio group and a button on it. When I click the button, the function should print out which radio was selected. I´m using a NSWindowController with xib file to show the Form.
The problem is, that the code continues running after showing the window.
So I tried a while loop with a property in my window which is set when I click the button.
But it does not work because I think the window is running in the same thread.
MyWindowController windowController = [[MyWindowController alloc initWithWindowNibName:#"MyWindow"];
[windowController showWindow:self];
while([windowController buttonClicked] == 0);
NSLog("Radio %# is selected!", [windowController selectedRadio]);
Do you have any idea how to wait for the window to close and than read out the data?
I hope you can help me.
You can add your self as delegate tao the window and listen for windowWillClosenotifications. That way you get informed when the windows is getting closed.
Note that you are not "waiting" on the window toi close, that wouldn't work without blocking the runloop, but you just sit idle until the delegate method is called. Also note that the window controller should be automatically a delegate to the window and thus could also be used for this.

NSWindow child window close on parent click

I need to implement a custom popover (cannot use NSPopover). Its all working fine, but I also need to implement that the popover closes itself when the user clicks somewhere in the parent window.
What's the best way to implement this, resp. how could this be implemented without subclassing the parent window?
Make the popover key window when showing it, and use NSWindowDidResignKeyNotification (or the delegate method) to close when it resigns that status (which happens when user makes some other window active). Closing whenever the parent window is closed is also a good idea (NSWindowWillCloseNotification).

Cocoa: programmatically show the main window after closing it with X

I want to programmatically re-open the main window of my Cocoa application after the user closed it with the X button.
I know it's still somewhere in memory but I don't know where.
If you're using the default Cocoa Application template, your app delegate has a reference to the window that's in MainMenu.xib. You can simply call
[window makeKeyAndOrderFront:self];
perhaps in an IBAction triggered by a menu item, to reopen the window. Note: be sure that the "Release when closed" and "One shot" boxes are unchecked in IB.
Surely, if the user closes a window they want it to go away. Reopening a window they just closed will most likely annoy them. If you, the programmer, disrespect their wishes, they will probably disrespect your program by moving it to the Trash.
If you want to make it impossible to close the main window, disable the close button. You can do this easily in interface builder on the Window attributes inspector.

Xcode Run IBAction when app loads

I would like to hide a window before the app has loaded. Now I know to hide a window you can use this;
[window2 orderOut:nil];
which works fine when you click on a button but what if I wont it to be hidden before or whilst the application has loaded?
So sorta need an IBAction on when the application loads
In Interface Builder, you can uncheck the box (in the window's attributes pane) that says to show the window at startup.
Or you can put that line of code in your app delegate's applicationWillFinishLaunching (or perhaps applicationDidFinishLaunching) method. (Might not work in the first one, I'm not sure.)
But I'd go with the first option, personally.