• 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: NSValueTransformer - Object Reference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSValueTransformer - Object Reference


  • Subject: Re: NSValueTransformer - Object Reference
  • From: Jonathan Younger <email@hidden>
  • Date: Sat, 17 Jul 2004 14:00:43 -0700

On Jul 17, 2004, at 10:36 AM, b.bum wrote:

On Jul 17, 2004, at 12:10 AM, Jonathan Younger wrote:
Is there anyway to get a reference to the object that the value transformer is bound to when the "- (id)transformedValue:(id)aValue" and "- (id)reverseTransformedValue:(id)aValue;" methods are called?

There is not. One possible workaround is to use the NSValueTransformer binding option to specify a specific instance of your NSValueTransformer that has a reference back to the controller. You'll need to do this programatically (see my previous post for an example).

However, with that said....

Generally, value transformers are intended to be stateless converters between type (a) and type (b). If you need state beyond, say, application level configuration information, then it is likely that there is an alternative architecture that is potentially simpler and certainly more in line with the intentions of value transformers.

I'm probably going about this the wrong way trying to use NSValueTransformer to accomplish what I need.


I'm trying to emulate something similar to a NSTableColumn using the arrangedObjects from an NSArrayController. I have an array of custom views where each view corresponds to a record in the array controller and I want the controls in the custom view to be bound like what can be done with binding a NSTableColumn.

For example with a NSTableView I could bind column 1 to arrangedObjects.someProperty and column 2 to arrangedObjects.someOtherProperty in an NSArrayController.
When the table view displays each record in the NSArrayController the NSTableColumns display the proper values for each record.

Each of the table columns contains a separate binding upon its own key path to the objects contained within the arrangedobjects. So, no magic there.

But there is some kind of magic going on that I don't understand. Each table column is bound to a separate key path with arrangedObjects.That handles which property to pull from the arrangedObjects. I understand this part. What I don't understand is how does the table column know which index in the arrangedObjects to display for each record? For example, index 0 of the arrangedObjects contains the value @"first record" for the arrangedObjects.someProperty key path and index 1 of the arrangedObjects contains the value @"second record" for the arrangedObjects.someProperty key path. How does the table column know which index to display? The only thing that I can think of is that NSTableView must be telling the column which index to display and is doing a lot of work behind the scenes setting and getting the values for the columns.


I'd like to do something similar and bind an NSTextField to arrangedObjects.someProperty and a different NSTextField to arrangedObjects.someOtherProperty in my custom view. When my custom views are displayed each view would display the proper record from the NSArrayController that the controls are bound to.

Why not bind the text fields to arrangedObjects.whateverProperty directly as you describe? That should "just work" (unless I'm misunderstanding the intent).

When I do this I get ("first record", "second record") displayed for the NSTextField value.

What I'm trying to do is something like the iTunes Smart Playlist done using Cocoa Bindings.




The alternative would be bind arrangedObjects directly to your custom view, then provide additional bindings on the custom view that specify which key should be used for each of the display components (or just hardwire until you need that level of flexibility).


I'm thinking that I might need to do something like this but am really not sure.



I've created a simple example illustrating what I'm trying to do if you'd like to download and try it out.
http://www.daikini.com/downloads/tmp/AccountManagerExample.zip


To try it out click the Add button under the Accounts table view. Then click the Add button under the Options table view. The Options table view binding works correctly and I can add/edit/remove values just fine and it works the way I would expect. The NSTextFields are dynamically added/removed but the binding is messed up as it shows all the values from the arrangedObjects and not a single value for each record like the table view below it does.



Thanks for your help,

Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSValueTransformer - Object Reference
      • From: Chris Hanson <email@hidden>
References: 
 >NSValueTransformer - Object Reference (From: Jonathan Younger <email@hidden>)
 >Re: NSValueTransformer - Object Reference (From: "b.bum" <email@hidden>)

  • Prev by Date: Re: Applescript error - NSCannotCreateScriptCommandError
  • Next by Date: Rounding to two decimals
  • Previous by thread: Re: NSValueTransformer - Object Reference
  • Next by thread: Re: NSValueTransformer - Object Reference
  • Index(es):
    • Date
    • Thread