NSPopupButton bindings with NSArrayController

Discussion in 'Mac Programming' started by satyam90, Jun 12, 2008.

  1. satyam90 macrumors regular


    Jul 30, 2007
    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?
  2. stadidas macrumors regular

    Feb 27, 2006
    Kent, United Kingdom
    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.

Share This Page