• 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: NSColorWell, setColor and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSColorWell, setColor and bindings


  • Subject: Re: NSColorWell, setColor and bindings
  • From: Dominique PERETTI <email@hidden>
  • Date: Tue, 22 Jun 2004 17:16:32 +0200

In fact i'm implementing my own color panel. This color panel sends an
action when a color is chosen. This action calls the colorwell's
setColor: . I don't really want to give the color panel the data and
keypath. It's up to the color well to notify the data model, I guess.
Actually, this is what it's supposed to do when a user picks a new
color.

The workaround I found is to subclass NSColorWell, and override bind
method to keep track of the controller it is bound to :

- (void)bind:(NSString *)binding toObject:(id)observableController
withKeyPath:(NSString *)keyPath options:(NSDictionary *)options
{
if ( [binding isEqual:@"value"] )
{
[self setMyObjectController:observableController];
[self setMyKey:keyPath];
}

[super bind:binding toObject:observableController withKeyPath:keyPath
options:options];
}

- (void)setColor:(NSColor *)color
{
[super setColor:color];

[[self myObjectController] setValue:[NSArchiver
archivedDataWithRootObject:color] forKeyPath:[self myKey]];

}

This works but I thought it was a bit overkill.


On 22 juin 04, at 17:05, Steve Sims wrote:

>
> On 22 Jun 2004, at 06:27, Dominique PERETTI wrote:
>
>> Hi,
>>
>> I have a NSColorWell bound in Interface Builder to some values that
>> works properly.
>> For some reason, I need to invoke this colorwell's setColor:
>> programmatically.
>>
>> The color changes... but bound observers are not notified !
>>
>> What am I missing ?
>
> From what you said above it sounds like you're calling setColor
> directly on the NSColorWell object in your UI. That's not the way to
> do it...
>
> What you need to do is set the colour value within your data model
> using setValue: forKey:. The UI's colour should update itself in
> response to that, as well as all other bound observers.
>
> If you just set values in the UI then you're actually bypassing the
> bindings system and your underlying model won't get updated.
>
> Steve
_______________________________________________
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.


References: 
 >NSColorWell, setColor and bindings (From: Dominique PERETTI <email@hidden>)
 >Re: NSColorWell, setColor and bindings (From: Steve Sims <email@hidden>)

  • Prev by Date: Re: NSColorWell, setColor and bindings
  • Next by Date: TIFF Error?
  • Previous by thread: Re: NSColorWell, setColor and bindings
  • Next by thread: Re: NSColorWell, setColor and bindings
  • Index(es):
    • Date
    • Thread