Re: Unusual Conditional Formatting
Re: Unusual Conditional Formatting
- Subject: Re: Unusual Conditional Formatting
- From: David Duncan <email@hidden>
- Date: Wed, 07 Sep 2016 10:14:09 -0700
> On Sep 6, 2016, at 3:10 PM, Frank D. Engel, Jr. <email@hidden> wrote:
>
> I am trying to set up what is apparently a somewhat unusual behavior:
>
> I have a formatter which I want to behave differently depending on an attribute of the value coming in, and on a user preference that can be toggled in the preference panel.
>
> Basically, they are all floating-point values, but they could be coming from several types of sources: for one type, I want it formatted one way (call it type S), and for other types, I want the formatting to be one of two things depending on the value of a checkbox in the preferences (type V or P). The value itself could be the same but should look different for the different types.
>
> I am hoping to do this in one formatter because these values are used in multiple text boxes and table row cells all over my interface, formatters are difficult or impossible to bind in XCode from what I can see, and different rows in a table (for example) may have different types in the same column.
>
>
> 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/.
Basically you are trying to add reference semantics (i.e. this the pointer identity of the number matters). This is probably going to end poorly for you to be quite honest.
Consider than on 64-bit platforms, NSNumbers are often represented as tagged pointers, so if you end up with a tagged pointer number that should have 2 “identities”, then you will end up with an effectively random result.
You will probably have a better result if you provide your own class that has the value and the type.
>
> 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.
>
> In a cell-based table, it seems to be working perfectly, but in a view-based table it is not. In an NSTextField which is not in a table, it is not.
>
> 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.
>
> When the preference is changed, I'm using an observer within the class for myThing to set value back to itself to try to trick the bindings to update to the correct formatting - this is working in the cell-based table, but does not seem to work in the standalone NSTextField (I haven't added that code to the view-based table yet).
>
> I'm seeing some other inconsistencies too that I am working through - is there an easier way to do this, or does anyone have any idea how I can try to diagnose what is causing the inconsistent behavior?
>
>
>
> _______________________________________________
>
> 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
--
David Duncan
_______________________________________________
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