PDA

View Full Version : NSPopupButton bindings with NSArrayController




satyam90
Jun 12, 2008, 02:22 AM
I am using Obj C with Cocoa and using XCode and IB.
In my window I added NSPopupButton. In my implementation I have NSArrayController which has a class ServerDetails (holds data related to linux server like hostname, IP address, etc).
I am able to link successfully only one detail to popup button. When I run the window, it shows all the sever's hostnames in pupup button that are available in array controller.
But I want to have popup button format something like "hostname - IP Address". How to bind two values of array controller to popup button?



stadidas
Jun 12, 2008, 06:12 AM
This is easy enough with NSTextField, as you can bind multiple values and express a pattern for combining those values into a single string.
What I would recommend would be to create a new property in your ServerDetails class called hostnameAndIP, and write an accessor method that returns the two strings concatenated:


- (NSString *)hostnameAndIP
{
return [NSString stringWithFormat:@"%@ - %@", hostname, IPAddress]
}

You could then bind the NSPopUpButton content values to the arrangedObjects of your NSArrayController with the model key path set to hostnameAndIP.