Re: basic bindings question
Re: basic bindings question
- Subject: Re: basic bindings question
- From: Ken Thomases <email@hidden>
- Date: Wed, 14 May 2008 23:09:49 -0500
On May 14, 2008, at 10:54 PM, Daniel Child wrote:
If I want to observe the property of an object, and in my case, it
turns out that the M and C are collapsed into a model-controller,
then it's basically a case of asking something to observe itself.
Well, it is sometimes desirable for an object to observe itself for
changes to its properties. However, it is often not necessary. In
particular, an object's properties should only be modified by
messaging the object, which gives you a perfect way to "notice" that
the change is being made -- right in the method which is invoked by
the message.
For example, if your controller's number property is being changed,
then something should be invoking its -setNumber: method. In that
case, you can just add your code for coping with a change to that
method:
- (void) setNumber:(NSNumber*)newNumber
{
if (newNumber != number && ![number isEqualToNumber:newNumber])
{
[number release];
number = [newNumber retain];
// Add code to cope with a change in the number property here
}
}
Can you be more specific about why you want your controller to
observe its own number property? What are you trying to accomplish?
I suspect there's another way to accomplish what you're interested in.
In other words, your "myFoo addObserver: self <THE CONTROLLER>
forKeyPath: @"number" becomes....
- (void) awakeFromNib {
[self addOberver: self forKeyPath: @"number" options: 0 context:
NULL];
There's a typo there. You've missed the "s" in "addObserver".
}
I tried that and got the same message as before (<receiver> may not
respond to addObserver), only this time the receiver is the
controller instead of number.
Can you report the exact message you're getting? Is it a compile-
time warning or a run-time exception?
Is it not possible to collapse M and C for a case where you want to
track a simple text field. It seems it must be.
It is possible. We'll have to see what's going wrong in your
particular case.
Cheers,
Ken
_______________________________________________
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