• 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: Value Transformer with multiple Model Key Paths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Value Transformer with multiple Model Key Paths


  • Subject: Re: Value Transformer with multiple Model Key Paths
  • From: Markus Spoettl <email@hidden>
  • Date: Sun, 30 May 2010 21:11:48 -0400

On May 30, 2010, at 3:51 PM, Mikael Wämundson wrote:
> I want to set the color of the text in each line in a TableView depending on two attributes of the object: one boolean and one integer. If the boolean is true all text for that line in the TableView is to be colored blue, if the integer is zero all text is to be colored red.
> In IB i've bound the TableColumns Text Color using the boolean as Model Key Path and a Value Transformer setting the text color to blue.
>
> Now, how do I setup a Value Transformer bound to the integer attribute and a Value Transformer?


I don't think you can solve this with just one value transformer because you have multiple values influencing the outcome. What I usually do in such situations is create an artificial property on the model object that combines the state of multiple properties into one value. In your case that properties could return

(a) another value that you transform into a color or

(b) it could return the color directly.

I know that violates the MVC paradigm, but it's a very simple and efficient solution - meaning least amount of code necessary. If you absolutely must maintain MVC you could create a proxy object that replicates all your model objects' properties + the calculated properties for display. Then you fill the table with proxies instead of the original objects.

Regards
Markus
--
__________________________________________
Markus Spoettl

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Value Transformer with multiple Model Key Paths
      • From: Quincey Morris <email@hidden>
References: 
 >Value Transformer with multiple Model Key Paths (From: Mikael Wämundson <email@hidden>)

  • Prev by Date: Re: NSFormatter: get default values
  • Next by Date: ANN: Accessorizer 2.0 released - Configuration Sets, custom formatting ... more intelligent view detection
  • Previous by thread: Re: Value Transformer with multiple Model Key Paths
  • Next by thread: Re: Value Transformer with multiple Model Key Paths
  • Index(es):
    • Date
    • Thread