Programmatically setting a binding with an NSValueTransformer

  • I have a CoreData app with an NSTableView, and I want the user to be
    able to
    add and delete the columns (from a given list).  I've been able to
    programmatically
    recreate all of the columns and their bindings except the ones that
    use a custom
    NSValueTransformer and NSPopUpButtonCell.  My questions are

    1) How do I bind the value transformer?  I haven't been able to
    figure out how
    from the documentation or examples on the web.

    2) How do I control the appearance of the popUpButtonCell?  The
    initial version
    (that I get from setting things up in IB) uses the style from IB's
    Cocoa-Data
    palette, but the programmatic version comes back with one looking
    like the
    one in the Cocoa-Controls palette.  It looks clunky inside a table view.

    I'm using XCode 2.4.1 and IB 2.5.4 on OS X 10.4.11.

    Thanks,

    Norm Hecht
  • On Dec 11, 2007, at 5:00 PM, Norm Hecht wrote:

    > I have a CoreData app with an NSTableView, and I want the user to be
    > able to
    > add and delete the columns (from a given list).  I've been able to
    > programmatically
    > recreate all of the columns and their bindings except the ones that
    > use a custom
    > NSValueTransformer and NSPopUpButtonCell.  My questions are
    >
    > 1) How do I bind the value transformer?  I haven't been able to
    > figure out how
    > from the documentation or examples on the web.
    >
    > 2) How do I control the appearance of the popUpButtonCell?  The
    > initial version
    > (that I get from setting things up in IB) uses the style from IB's
    > Cocoa-Data
    > palette, but the programmatic version comes back with one looking
    > like the
    > one in the Cocoa-Controls palette.  It looks clunky inside a table
    > view.
    >
    > I'm using XCode 2.4.1 and IB 2.5.4 on OS X 10.4.11.

    you can specify the transformer by name or object as par of the
    options dictionary

    the constants are named in the docs for
    bind:toObject:withKeyPath:options:\

    NSString *NSValueTransformerNameBindingOption;

    NSString *NSValueTransformerBindingOption;
  • On Dec 11, 2007, at 5:00 PM, Norm Hecht wrote:

    > I have a CoreData app with an NSTableView, and I want the user to
    > be able to
    > add and delete the columns (from a given list).  I've been able to
    > programmatically
    > recreate all of the columns and their bindings except the ones that
    > use a custom
    > NSValueTransformer and NSPopUpButtonCell.  My questions are
    >
    > 1) How do I bind the value transformer?  I haven't been able to
    > figure out how
    > from the documentation or examples on the web.

    Norm,

    I've done this with a named custom transformer, but it relies on you
    having registered your custom transformer with NSValueTransformer.

    {
    NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
    [bindingOptions setObject:MyCustomTransformerName
    forKey:NSValueTransformerNameBindingOption];

    [myColumn bind:@"value" toObject:someController
    withKeyPath:@"arrangedObjects.someValue" options:bindingOptions];
    }

    To just use an instance of your custom transformer...

    {
    id transformer = [[[MyCustomTransformer alloc] init] autorelease];

    NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
    [bindingOptions setObject: transformer
    forKey:NSValueTransformerBindingOption];

    [myColumn bind:@"value" toObject:someController
    withKeyPath:@"arrangedObjects.someValue" options:bindingOptions];
    }

    Bill
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today