Ok,
In XCode 4 I have created 3 small programs: A calculator, a 'scratch pad' (blank note-type window), and 'spread sheet' (just looks开发者_运维问答 like a spread sheet, for holding values gained with the calculator)
What I'm trying to do now is add a button to my calculator that will, when pressed, execute either the scratch pad or the spread sheet and give the user the option of which one to pick.
I've placed both the bundles in the 'applications' folder so they are easy to find.
I was wondering if I need to subclass an NSButton or if there is an easier way to do it.
I was thinking that I could just make the NSButton open a file-browser at /users/me/applications and then when the user (me :-) ) chooses one of the applications it will just store it as a variable that the button will then execute when I press it's key-equivalent.
But then I don't know how to give the button two different actions, a 'click' and a 'press'
If I have to subclass the button, where should I begin looking? And if there's an easier way, where would that be?
Seems like the simple solution would be two buttons, one for each program.
If you're set on using just one button, then the straightforward thing to do is to have the button's action display a sheet or dialog box that lets the user decide which application to launch.
I like this approach, it sounds nice. Is there any way to make it so that the menu allows me to decide which of the programs the button will run, and then pressing its 'keyboard equivalent' will actually launch the program? – TotalCocoaNewb
Certainly so:
-(IBAction)theActionYouSetOnThePopupButtonInInterfaceBuilder:(NSPopUpButton*)sender
{
if ( 0 == [sender indexOfSelectedItem] ) {
// do something...
} else {
// do something else...
}
}
精彩评论