objective c - Observing NSUserDefaultsController not working when bound properties are set -
Here's the setup: I have a subclass of IKImageBrowserView zoomValue
property is bound to a key In VFBrowserZoomValue
shared NSUserDefaultsController
. I have the NSSlider
whose value
binding is bound to the same key.
This works perfectly to change the zoomValue
browser from the slider.
I am trying to implement -magnifyWithEvent:
in my code; Trackpads with pinch gesture to zoom the browser to my IKImageBrowserView
subclass.
Here's my implementation:
- (zero) magnifyWithEvent: (NSEvent *) event {if ([increase incidence]> gt; {if ([self ZoomValue] & Lt; 1) {[Self set zoom value: [self zoom value] + [Event magnification]];}} And if ([event magnification] <0) {if ([self zoom value] + [Event increment ]> 0.1} {[set zoom value: [self zoom value] + [event magnification]];} and {{auto set zoom value: 0.1];}}}
The problem is that the zoomValue
of the browser changes correctly NSUserDefaults
the new value The update has not been updated.
Somewhere else in the app, I have -observeValueForKeyPath: ofObject: change: context:
which looks for the browser's zoomValue
If I log the value of the browser's zoom, the value of the slider and the key to the defaults in that method, I think the browser's zoom value has not been pushed into NSUserDefaults and the slider has not been updated.
I ' -MagnifyAvent:
To call the call to along with the call Triish is - {will, will} ChangeValueForKey
no effect
The KVO flow for binding is not orthogonal; A bond is not an property , it is reference for a property. It is a rhythm to remember how binding works:
- < Li> KVO is used to change the model from the controller & amp; See.
- KVC is used to control controller from view & amp; Model
Thus when a scene with binding handles events, then its properties need to refer to the context of its binds.
Your code may look like this here, with a utility method to carry heavy loads of publicity changes via binding:
- (zero) Magnavet Event: (NSECT *) event {if ([Event Magazine]> gt0) {if ([self zoom value]) 1 [{Self set zoom value: [self zoom valle] + [Event magnification]]; }} And if ([event magnification] <0} {if ([self zoom value] + [event magnification]> 0.1) [[self set zoom value: [self zoom value] + [event magnification]]; } And {{auto set zoom value: 0.1]; }} // update which is related to our zoom value. [Self Update Value: [NSNumber Number Blast: [Self Zoom Value]] To Force: @ "Zoom Vale"]; }
It is a very unfortunate that ImageKit requires the use of @ "zoomValue"
in the context of the zoom value binding of IKImageBrowserView, the most in the epiket Binding global string continuous such as NSContentBinding
.
And this is the general utility method for promoting change through binding here:
- (zero) Update Update: Binding for (id) value: ( NSString *) binding {NSDictionary * bindingInfo = [self information: binding: binding]; If (BindingInfo) {NSObject * Object = [Binding Object Forekey: NSOBZED Objects]; NSString * keyPath = [Byinginfo ObjectForekey: NSOBKKPaPhechek]; NSDictionary * Option = [Binding Object Forekey: NSOption KA]; Use options to apply // value transformer, placeholder etc. Values = value converted to value id; // Exercise for reader // Model or controller object has been replaced with new value [Object set value: changed for keypath: keypath]; }}
Actually left as an exercise for placeholders, value transformers, and readers.
Comments
Post a Comment