• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSCell subclass with custom binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCell subclass with custom binding


  • Subject: Re: NSCell subclass with custom binding
  • From: Scott Stevenson <email@hidden>
  • Date: Sat, 21 Oct 2006 14:49:31 -0700


On Oct 21, 2006, at 8:40 AM, Stephan Cleaves wrote:

Since the binding is custom the NSTableColumn cannot be bound to it because of course it knows nothing about it. I'm not sure if there is a way to get NSTableColumns to know about new bindings programmatically.

You can't do it graphically, but you can usually do it programmatically using the KVB protocol methods. In fact, you can even bind things that aren't explicitly exposed (at least sometimes).



I don't know exactly what NSTableColumn does to correctly provide the NSCell with its value but it seems like it probably gets the value via the binding and iterates over the values for the visible cells.

The table column will just use whatever keypath you give it. So if you bind its 'value' property to:


	SomeArrayController.arrangedObjects.name:

It will call 'name' or 'setName' on each model object. The result of 'name' on the model object will be set as the object value for the cell that is currently being displayed.

I haven't done exactly what you're describing, but I think if your subclass does the right thing in -value and -setValue (and by "right thing," I mean properly update its display), then I *think* you should be set.


Anyway, my questions are: Is there a way to get NSTableColumn to know about custom bindings either programmatically or through IB

It should be something of the flavor:

[column
    bind:@"value"
    toObject:arrayController
    withKeyPath:@"arrangedObjects.someProperty"
    options:nil];

You'd probably make something method called -setupCustomBindings and call that in -awakeFromNib.


There is also no point in binding the NSActionCell subclass itself because it only wants a single value and binding to arrangedObjects.bindingname of the NSArrayController would result in an array.

You could also possibly get away with dropping an NSButtonCell in your table in IB (since it's an action cell), setup the bindings in IB as well, then swap in your custom data cell at runtime. If that works, it would be a simpler solution since you don't have to setup bindings programmatically.


I did something like this, but with an NSImageCell subclass instead:
http://theocacao.com/document.page/196

    - Scott

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSCell subclass with custom binding
      • From: Stephan Cleaves <email@hidden>
References: 
 >NSCell subclass with custom binding (From: Stephan Cleaves <email@hidden>)

  • Prev by Date: Re: tracking mouse state outside of a view
  • Next by Date: Re: Text character under the mouse cursor in an NSTextView
  • Previous by thread: NSCell subclass with custom binding
  • Next by thread: Re: NSCell subclass with custom binding
  • Index(es):
    • Date
    • Thread