Re: textfield not updating with bindings - Whats wrong?
Re: textfield not updating with bindings - Whats wrong?
- Subject: Re: textfield not updating with bindings - Whats wrong?
- From: Kieren Eaton <email@hidden>
- Date: Sun, 24 Aug 2008 11:53:22 +0800
On Aug 23, 2008, at 5:16 AM, Kieren Eaton wrote:
ok the delegate is set as an object in IB it is the delegate of
Files owner and nsapplication (thats correct isnt it?) it has a
class of bindtestdelegate which is where the button action is
located.
The button calls the changeValues method in the delegate class which
then calls the updateValues in the fooClass instance
of the someclass.
should my filesOwner in IB (Currently it is NSApplication) be
something different?
Well, that depends, in most cases it's good to have a
NSWindowController or NSViewController as file owner since those take
care of memory management of the nib file. But I believe it's
irrelevant to the problem at hand.
the instance of someClass is just dragged straight out of the IB lib
as a simple object and assigned the class "someClass"
I dont actually have a "nsobjectcontroller subclass" .h/.m in my
project but according to the apple docs I dont need one?
No, you don't, you just mentioned you used one.
As far as I can tell from your explanation, you have 1
bindingstestDelegate object (the file's owner) and one extra someClass
object. The problem is that your delegate class creates its own
someClass instance and when you press the button that instance get
changed, not the other instance you created in the nib file.
Thats correct. I was not realising that the instance created in code
and the one from the nib were not the same.
I would change the code so that the bindingstestDelegate class exposes
a readonly property named fooClass. You then remove the extra
someClass object from your nib and bind the NSTextFields to the file's
owner "fooClass.someString" and "fooClass.someNumber" keys.
I did that and it worked! thanks very much. This has increased my
comprehension of bindings a lot.
just for my own benefit i also tried adding an instance on an object
controller to the nib and set its content outlet to the
bindingstestDelegate. Then I bound one of the textfields to the
object controller with
controller Key = selection
model Key = fooClass.someString
this also worked. YAyY :)
I have one minor question now that I am understanding bindings more.
Is is good policy to add an object controller instead of just binding
directly to the class?
I would also suggest you change the naming slightly, using uppercase
first characters for class names. This makes it easier to distinguish
classes from instances, methods and properties. More details here:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_12.html#/
/apple_ref/doc/uid/TP30001163-CH3-TPXREF108
Thanks and I do always use these conventions, except in this case
where I just wanted a quick and dirty test case for my own learning.
I did not expect to be posting it on this list, so apologies for the
bad form on class and instance names etc.
Thanks very much for your help.
Now its onto much bigger things.
Kieren
_______________________________________________
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