I am trying to come to grips with how difficult it is to use NSPopUpButton. It's by far and away the most difficult user element to program in Cocoa (at least as far as I am finding it).
The use case I have in mind is as follows:
- I have a class called Port that represents a Serial port.
- Amongst the attributes is a name field.
- In the NSPopUpButton I want to display the name field for each port.
- When a user selects a specific port it is marked in the pop-up with a tick as expected
- When the user subsequently hits a connect button I can ascertain which of the Ports from the Array was selected.
- I would like to achieve this using bindings as I think once I get my head around it, it will be the more elegant solution.
Therefore in my AppController.h I am expecting two attributes which I can presumably create as properties and synthesize:
NSMutableArray *allPorts;
Port *currentlySelectedPort;
and one action in my .m:
-(void)didSelectConnect:(id)sender{
NSLog(@"Selected port name is:%@",[currentlySelectedPort name]);
}
in Port.h I have
NSString *name;
NSString *baudRate;
... etc ...
I have created a simple project which contains just a pop up (and a label) and following various articles, I have managed to populate an NSMutableArray with elements which I then use an ArrayController to display values and then on selection set the value of a label (using an object controller). However, as much as this is clever it doesn't fit the use case I am trying to implement. So I turn here for help
M