Bindings and Observing
Bindings and Observing
- Subject: Bindings and Observing
- From: Laurent Daudelin <email@hidden>
- Date: Wed, 24 Mar 2010 23:42:31 -0700
I have an application where I would like to bind the preferences UI items to the a NSUserDefaultsController. That part is easy. The next part I would like to do is add my preferences controller as an observer for those properties that would be managed by the controller. That had me stumped a bit.
I have looked at the Sketch+accessibility sample and although it does what I would like my app to do, namely calling one of my controller's method when the user changes a preferences (so that I can use the new value right away), I am confused on how they achieve it.
In the Preferences.nib file, the checkbox and the textfield are bound to the defaults controller. So far, so good. In the application delegate's applicationWillFinishLaunching:, they have those 2 lines:
[self bind:SKTAppAutosavesPreferenceKey toObject:userDefaultsController withKeyPath:[@"values." stringByAppendingString:SKTAppAutosavesPreferenceKey] options:nil];
[self bind:SKTAppAutosavingDelayPreferenceKey toObject:userDefaultsController withKeyPath:[@"values." stringByAppendingString:SKTAppAutosavingDelayPreferenceKey] options:nil];
The app delegate, by binding these properties to the user defaults controller, then has its setAutosaves: and setAutosaveDelay: methods called each time the checkbox is toggled or the text field value is changed. How does that work behind the scene? The user defaults controller of course has the keys saved in the user preferences set in IB. Maybe it's late but I fail to understand this.
-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin http://nemesys.dyndns.org
Logiciels Nemesys Software email@hidden
Photo Gallery Store: http://laurentdaudelin.shutterbugstorefront.com/g/galleries
_______________________________________________
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