Reputation: 111
I am trying to get a basic understanding of Cocoa Bindings and I would like to create a really simple project. I have a class Person
which has a variable name
of type NSString
. Here is how I want things to work:
Person
class.Person
class) automatically changes its value according to the name
variable of the Person
instance.I've spent hours reading various tutorials and the Apple Mac Developer Library, but each and every example only shows how to get Cocoa Bindings work with tables. When I try to develop something far more simpler I feel that I am completely lost. I have created a base project and the only thing left is to make all the bindings. I am kindly asking to make all the connections for me and hopefully provide me with an explanation. https://www.dropbox.com/sh/6hddfxyitqp6uoc/AACgaRhKBhLo6EXCVN9W6GQua?dl=0 The project is a document-based app because I will be developing an app of this type in the future.
Upvotes: 1
Views: 1943
Reputation: 15589
There are several reasons why your project doesn't work so lets start again and create the simplest Cocoa Binding Example.
Prepares Content
on.Value
to Object Controller
, Controller Key selection
and Model Key Path name
.Value
to Object Controller
, Controller Key selection
and Model Key Path name
.The controller automatically creates an instance of NSMutableDictionary
which is KVO compliant for every key. When the contents of the Text Field is changed, the binding of the Text Field calls setValue:@"New Contents" forKey:@"name"
. This notifies the binding of the Label and the Label is updated.
Why your project doesn't work:
[<Document 0x618000100750> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.
. Remove this connection.name
instead of an ivar. You don't have to use setValue:forKey:
to change the name in code, person.name = [field stringValue]
is ok.init
method of the document. This is too early, the xib isn't loaded yet and the controller doesn't exist. Set the content in windowControllerDidLoadNib
. Instead of addObject
I would use setContent
but addObject
should work.Upvotes: 7