I want to have a button where if I click it, then some text is displayed that says "you clicked the button." I know how to do this using IBOutlet and IBAction. Can it be done with bindings? If so, then how?
I don't think so. You can't bind a momentary button to a property and expect that to work correctly. What would you bind on the button side? After pressing and releasing a momentary button, the button's state is unchanged, so there's nothing to bind do.
Related
so i have a simple NSMenu. It is attached to a Status Item Button.
When i click the Button it pops Open.
Now my Problem is that as soon as i click outside of the NSMenu, it closes. How can i avoid that ?
I did try many things but cant get that to work.
The reason i need that is that when the user clicks something in the NSMenu, another window opens, and while this window is open i also want the NSMenu to stay open. But it just does not work.
I feel like its impossible.
Many Thanks in advance.
I believe you have to create a custom view that pops up but something that could be done natively with just NSMenu.
I'm using a NSAlert to ask the user to enable Accessibility for assistive devices. Is it possible to have a button that does not close the NSAlert that I could use to just open the UniversalAccess prefpane ?
If not, I suppose I've to create myself that window.
Thx.
Normally alerts close when any button is pressed. In Mac OS X 10.5 or later you can use setAccessoryView: to insert a custom view into the alert, which presumably can contain a button that does anything you want.
Note however that you can't specify where the accessory view goes. It might have a button in it but the button would show up in the middle of the window instead of along the bottom with the other buttons. (If you chose a different button style such as a square bevel for your custom button, it might look less out of place.) To have complete control over layout, you need to make your own alert window.
Hi I implemented an NSPopover in one of my apps, but the popover will not close. I'm guessing that it should close once I click something else, but its not. I know that there's a close popover action but that only works for a different button. How can I make it look to see that the popover is open and when it is open to close the popover when I press the same button?
I solved the problem!
First go ahead and click your .xib file.
Where you see the first responder box and files owner - click on the popover.
On the sidebar go to the attributes center
Change the behavior from Application-Defined to Transient and it should work!
That should make the popover disappear once someone has clicked outside the popover.
Another way to close the popover is to have a separate button.
Just add another NSButton and then link it to the popover on the sidebar and set it to Received actions -> perform close:
I need to simulate a button press on my Cocoa button programatically and I am trying to do this on cocotron which unfortunately does not have the NSEvent method: mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:
implemented. Is there anyway to programatically simulate a button press without having to create an event?
Don't forget to look in superclasses when you're looking for something. All NSControls, including all NSButtons, respond to a performClick: message.
That said, is it really appropriate for you to simulate a button press? If you just want something done, it's generally better to directly tell the controller to do it.
I am trying to interface with a cocoa popup menu from an OpenGL button. The actual button needs to be in OpenGL and I cannot stick an actual Cocoa button in its place but when this button is pressed I would like for a Cocoa menu to popup just like the one that comes up when you press the nspopupbutton. It seems that there is no way to get this popup window to come up by itself so I wanted to just insert an invisible button and have it be pressed automatically when the popup menu method is called. Is there a way to programmatically set a button to pressed (this will bring up the menu from the popupbutton) and make the button itself invisible without making the resulting menu invisible?
It seems that there is no way to get this popup window to come up by itself
Sure there is. See + popUpContextMenu:withEvent:forView:
Have you thought about just using a regular NSMenu, rather than trying to finagle the menu from an NSPopupButton?