• 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: Unusual Conditional Formatting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unusual Conditional Formatting


  • Subject: Re: Unusual Conditional Formatting
  • From: "Frank D. Engel, Jr." <email@hidden>
  • Date: Wed, 07 Sep 2016 21:00:26 -0400

Tried adding the suggested KVO code - does not seem to have made a difference.

Already had #2 - not sure that #1 is practical in this situation.


On 9/7/2016 05:25, Jonathan Mitchell wrote:
A couple of suggestions.

Here is what I have so far: I used a category on NSNumber to add a "valueType" attribute as described at http://nshipster.com/associated-objects/.

The formatter checks this and the user preference when formatting an incoming value.  It sets some instance variables on itself to remember what it last saw so that it can correctly default its interpretation of an entered value when trying to send it back.


On your associated object setter add KVO support.

- (void)setValueType:(int)valueType
{
     [self willChangeValueForKey:@"valueType"];
     objc_setAssociatedObject(self, @selector(valueType), @(valueType), OBJC_ASSOCIATION_RETAIN);
     [self didChangeValueForKey:@"valueType"];
}



The binding for the values is indirect - to the effect of "myThing.value" - and if I change "myThing" but the new thing has the same numeric value, the formatter does not always seem to trigger to render the value in the correct format - it holds that of the previous thing.  If I change the value from another control, when the bindings update the field, the formatting is suddenly corrected.
The formatter will only receiver the value part of “myThing.value”.
It may well be that the formatter doesn’t re-format because the actual value doesn’t change - formatting may be an expensive operation.
In this case you may want to reformat so:

1.  consider Manual triggering of reformat if valueType changes.
2. Try overriding NSFormatter -stringForObjectValue: - that should give you a low enough foothold into the rendering.

HTH

J


_______________________________________________

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


_______________________________________________

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


References: 
 >Unusual Conditional Formatting (From: "Frank D. Engel, Jr." <email@hidden>)
 >Re: Unusual Conditional Formatting (From: Jonathan Mitchell <email@hidden>)

  • Prev by Date: Re: C callbacks with NSNotificationCenter?
  • Next by Date: Re: Unusual Conditional Formatting
  • Previous by thread: Re: Unusual Conditional Formatting
  • Next by thread: Re: Unusual Conditional Formatting
  • Index(es):
    • Date
    • Thread