On 31 Dec 2008, at 3:25 pm, Chunk 1978 wrote:

i have a few checkboxes in my prefs window which are bound... however,
i was under the impression that i could easily set the very first load
state of these boxes in IB by checking "Selected" (Inspector >
Attributes > Visual > Selected) before the userdefaults are written...
it doesn't seem to work... should this work or am i just dreaming?  do
i really have to write code for this?  and if so, what's the use of
being able to check Selected in IB?


First off, I'll declare my lack if in-depth knowledge about bindings.

But seems to me you wouldn't expect this to work. A UI widget is only representing a state in your data model, it is not the model (or shouldn't be). So trying to set some initial state in your model by checking the UI in IB is backwards. Instead your code should be initialising the state of the model to a desired state, then the UI will follow (automatically, if its bound).

With preferences (user defaults) there is an API for registering the desired initial first state: -registerDefaults:

The use of setting the state in IB is, I guess, that sometimes you will know that a given state defaults to YES. But to be honest I would never rely on it - you should always set a UI to match the data model state it is viewing. With KVO (and by extension, bindings) this is taken care of pretty much for you.

You don't need to write any code to deal with this, except one line at app start-up that reads your default state from a plist and calls - registerDefaults: with it. If your app needs to set certain defaults in order to work you'll have to do that anyway.

--Graham


_______________________________________________

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 arch...@mail-archive.com

Reply via email to