Hiding a button with multiple windows? - Objective C OSX - objective-c

I have an application which has a button on the first window, once pressed this button should hide and perform an action, to hide the button i'm using this code:
[self.myButton setHidden:TRUE];
This works fine until I have multiple windows - new instances of this window do not have this button it's hidden by default. However when I create a new window and press the myButton on the first window it doesn't hide the button.
Furthermore if I create a new window and then close that window and press the myButton on the first and now only window it crashes.
Any ideas how to overcome this?

myButton is pointing to the button in the last window you opened

Related

Activate all windows from background when clicking on main window

I have an Objective-C application with a main window and a small progress window with a stack view to show the current progress.
If the application is put in the background by activating any other application and then clicking on the Dock icon, both the Main and secondary windows is brought to the front and shown.
But, if I just click one of the windows when in the background, only that window is activated and brought to the front, the other stays in the back.
I want to implement so that when I click on the main window it does the same thing as clicking on the Dock icon, it should show both windows on top with the Main window activated.
But if I click on the progress window, I don't want the main window to be brought to the front.
I haven't been able to find a way to do this, how should I go about achieving this?
You can detect the window being clicked with the window delegate's -windowDidBecomeKey: or -becomeKeyWindow, or the app delegate's -didBecomeActive:.
Then depending on your exact needs, you can use [NSApp activateIgnoringOtherApps:] or [[NSRunningApplication currentApplication] activateWithOptions:] (and possibly NSApplicationActivateAllWindows).

NSButton makeFirstResponder

I have a simple Mac app with a window. In this window, I have two NSTextfields and one NSButton.
When the window appears, the first NSTextfield has the focus. I press enter and the focus passes to the second NSTextfield. I press enter again and the focus passes to my button.
[myWindow makeFirstResponder:myButton];
This works fine but now when I press enter again, I expect that the button is clicked, but it does not happen.
On a Mac, spacebar is what you press to select a button. This is the same for a selecting the value of a dropdown, radio button, or check button.

Pop up window dialogs

In Cocoa, my application's main window has a button. How can I make it so when you click it, a new window will be generated and set focus to such window so that the main window can not be clicked or interacted with at all? This new window will have a textfield and a submit button. You click it and the window is supposed to close and send the textfield's data back to the main window (and it will recover focus as well).
I found this: How to open a new window on button click in Cocoa Mac Application?
But the answer doesn't seem to be working for me. The function showWindow doesn't seem to be recognized...
You're trying to create a modal window.
You can see the documentation at http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/WinPanel/Concepts/UsingModalWindows.html for the full details.
Assuming you have created the window in your nib and can access it via an Outlet, you can call
[NSApp runModalForWindow:myWindowOutletVariable];
to make it modal like you want.

Set tab order in Mac app window

I'm creating a login form that's loaded from a nib. I have several NSTextFields, but when the app is launched, the one that gains focus immediately is the last one I added to the form. How do I set up the tab order and change or remove the initial focus?
In the Interface Builder: Right click on the NSTextField, link the nextKeyView with the object you want to be the next one that should be activated by pressing the "tab" button.
There's also an option called "Refuse First Responder". This option avoids the blue frame.

NSTableView in NSDrawer issue

Currently i am developing a app with a borderless window and a NSDrawer within the borderless window,and there is a NSTableView in the drawer.
Problem is when i select a row in the table,and then click the miniaturize button i create manually in the borderless window,it's useless,nothing happens.but when i close the drawer,the miniaturize button works fine.
Try sending -close: to the drawer before miniaturizing the window.