NSPopupButton bindings with NSArrayController

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

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    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. macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #2
    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.
     

Share This Page