On Aug 14, 2008, at 8:20 PM, Ron Lue-Sang wrote:
Hmm yea, that's a bummer.
If I were building the views you're using, I'd publish another binding in/from those views. Like "dataType" or "ridiculouslyLongGermanStyleNameDescribingWhatTheBindingIsFor".

And then your views would really have two inputs and you'd actually draw differently in your drawRect method because you can change your view state in response to the KVO notification your view gets from the 2 things it's bound to - and the handling of the KVO notification can safely do [self setNeedsDisplay] and know that that's gonna work.

Interesting idea I'll keep that in mind...

But I bet you're just trying to use plain old textFields. Yea?


Exactly, that's the main problem. My own custom views don't use bindings, they use KVO more directly so I can make this work more easily.

I think I may have found a way that might be feasible in a more automated way, though. When I get a KVO notification for the preference change in the (window/view) controller, I can unbind the text field and bind it again. Since I can get all binding properties using -infoForBinding: I can automatically rebind the whole thing without hardcoding (except for the binding name). The only thing that I have to do is setting it up correctly but it looks like it works fine:

- (void)rebind:(NSObject *)object binding:(NSString *)binding
{
    NSDictionary *bindingInfo = [object infoForBinding:binding];
NSObject *observedObject = [bindingInfo objectForKey: NSObservedObjectKey]; NSString *keyPath = [bindingInfo objectForKey:NSObservedKeyPathKey]; NSDictionary *bindingOpts = [[[bindingInfo objectForKey:NSOptionsKey] retain] autorelease];

    [object unbind:binding];
[object bind:binding toObject:observedObject withKeyPath:keyPath options:bindingOpts];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"metricUnits"]) {
        [self rebind:tempField binding:@"value"];
    }
}

This can also be done as a category on NSObject for reuse purposes. I'm wondering as to whether this has any side effects that I'm not aware of? I certainly can live with that kind of manual work, though its not nearly as elegant as your suggestion.

Regards
Markus
--
__________________________________________
Markus Spoettl

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to