• 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: Custom bindings in a control/cell pair
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom bindings in a control/cell pair


  • Subject: Re: Custom bindings in a control/cell pair
  • From: Ricky Sharp <email@hidden>
  • Date: Thu, 24 Feb 2005 11:58:10 -0600

Wanted to post an update...

I finally have a working example.  Currently, I have two implementations of the bindings code: one lives in the control; the other in the cell.  It may be possible to remove some redundancy, but I'm tabling that for much later.

The reason for past crashes and/or console errors in my control/cell palette was I didn't have things set up to work with nil values.  I'm going to have to dig a bit more into this as my control and cell both provide an override for setNilValueForKey.

I didn't run into such issues in my first palette item (a view).  In both cases, I added a binding to work with an NSColor property.  Perhaps the view item is also at risk and that the problem didn't yet present itself there.


As a temporary workaround, I do this in my control setter:

- (void)setEnabledTextColor:(NSColor *)newEnabledTextColor
{
NSLog (@"setEnabledTextColor:%@ cell = %@", newEnabledTextColor, [self cell]);

    if (newEnabledTextColor == nil)
        [[self cell] setEnabledTextColor:[NSColor blackColor]];
    else
        [[self cell] setEnabledTextColor:newEnabledTextColor];

    [self setNeedsDisplay:YES];
}

It seems a bit odd though that setEnabledTextColor was being called directly with a nil value.  In my observeValueForKeyPath:ofObject:change:context:, I ultimately use setValue:forKey: to change a property.

Hmm..just glanced at the docs for setNilValueForKey:  It mentions that it's indeed invoked by setValue:forKey:, but seems to do so only when setValue:forKey: was given a nil for a scalar value.

Time to take a step back a bit and read up on strategies to work with nil values.  At first glance, I may just beef up my cell accessors to handle the nil values (basically just substitute them for a default value; e.g. color would be [NSColor blackColor]).  My control accessors would then remain simple call-throughs.

And then add similar safeguards to my view classes.


Finally, while ulimately I won't be able to post my palette items as sample code, I will create a stripped down version of a palette and corresponding app.  They will contain three palettized items: a view, a control and a cell.  All three will contain a scalar attribute and an object attribute.  That should cover all the bases.

--
Rick Sharp
Instant Interactive(tm)

 _______________________________________________
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: Working with nil values [was Custom bindings in a control/cell pair]
      • From: Ricky Sharp <email@hidden>
References: 
 >Custom bindings in a control/cell pair (From: Ricky Sharp <email@hidden>)
 >Re: Custom bindings in a control/cell pair (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Binding name must be same as ivar name?
  • Next by Date: Re: Binding name must be same as ivar name?
  • Previous by thread: Re: Custom bindings in a control/cell pair
  • Next by thread: Re: Working with nil values [was Custom bindings in a control/cell pair]
  • Index(es):
    • Date
    • Thread