Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
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?
 
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:
Code:
- (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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.