FROM : George Orthwein
DATE : Wed Aug 30 08:24:57 2006
On Aug 29, 2006, at 11:42 PM, Trygve Inda wrote:
> How would you bind it to the controller vs the model? Can you give an
> example?
>
> My object has an instance variable "dict" and I bind the controls
> (mostly
> checkboxes) to dict.someKeyName.
>
> Trygve
I had to try out a test app since I've been working with Core Data
lately. My normal bindings are a little fuzzy, I'm afraid.
To a new project I simply added an NSObjectController which defaults
to the class NSMutableDictionary. I added some keys and checked
"automatically prepares content". I bound some checkboxes to those
keys. I also added a button to log the dictionary by displaying
[objectController content].
What I found was that the dictionary was empty upon launch, not what
I expected! So I also tried creating a model class to use as the
Object Controller's content. Still empty on launch. So then I bound
to the model directly. Same thing.
I think I figured out the difference though. My experience has been
with a custom view. I believe Views do get sent the initial values of
the Model upon binding. For example, if I initialized the dictionary
in the model's init method, so that a key was set to "on", then the
corresponding checkbox was selected on launch since it was getting
sent the bound value.
But instead of the view, you want the model to get default values.
Turns out a controller won't help that any. Sorry. Listen to Matt,
not me. :)
(I thought maybe there would be a way to enumerate through the
controls to send their values to the model, but just setting the
defaults initially would be easier anyway.)
George
DATE : Wed Aug 30 08:24:57 2006
On Aug 29, 2006, at 11:42 PM, Trygve Inda wrote:
> How would you bind it to the controller vs the model? Can you give an
> example?
>
> My object has an instance variable "dict" and I bind the controls
> (mostly
> checkboxes) to dict.someKeyName.
>
> Trygve
I had to try out a test app since I've been working with Core Data
lately. My normal bindings are a little fuzzy, I'm afraid.
To a new project I simply added an NSObjectController which defaults
to the class NSMutableDictionary. I added some keys and checked
"automatically prepares content". I bound some checkboxes to those
keys. I also added a button to log the dictionary by displaying
[objectController content].
What I found was that the dictionary was empty upon launch, not what
I expected! So I also tried creating a model class to use as the
Object Controller's content. Still empty on launch. So then I bound
to the model directly. Same thing.
I think I figured out the difference though. My experience has been
with a custom view. I believe Views do get sent the initial values of
the Model upon binding. For example, if I initialized the dictionary
in the model's init method, so that a key was set to "on", then the
corresponding checkbox was selected on launch since it was getting
sent the bound value.
But instead of the view, you want the model to get default values.
Turns out a controller won't help that any. Sorry. Listen to Matt,
not me. :)
(I thought maybe there would be a way to enumerate through the
controls to send their values to the model, but just setting the
defaults initially would be easier anyway.)
George
| Related mails | Author | Date |
|---|---|---|
| Trygve Inda | Aug 29, 14:16 | |
| Matt Neuburg | Aug 29, 19:20 | |
| Trygve Inda | Aug 29, 23:48 | |
| Matt Neuburg | Aug 30, 00:16 | |
| George Orthwein | Aug 30, 03:23 | |
| Trygve Inda | Aug 30, 05:42 | |
| George Orthwein | Aug 30, 08:24 | |
| Trygve Inda | Aug 30, 14:30 |






Cocoa mail archive

