I am trying to understand how difficult it is to use NSPopUpButton. This is far and far the most complex user element for programming in Cocoa (at least as far as I find it).
The use case that I mean is as follows:
- I have a Port class that represents a serial port.
- Among the attributes is a name field.
- In NSPopUpButton, I want to display a name field for each port.
- When the user selects a specific port, it is marked with a checkmark in the pop-up window, as expected
- When the user subsequently clicks the connect button, I can determine which of the ports from the array was selected.
- I would like to achieve this using bindings, as I think, as soon as I get my head around, it will be a more elegant solution.
Therefore, in my AppController.h, I expect two attributes that 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]); }
at Port.h I have
NSString *name; NSString *baudRate; ... etc ...
I created a simple project containing only a pop-up window (and a label) and following various articles, I managed to populate NSMutableArray with elements, which I then use an ArrayController to display the values, and then, when I select, set the label's value (using the object controller). However, as smart as it is, it is not suitable for the use that I am trying to implement. Therefore I seek help
M
objective-c cocoa macos
Clokey
source share