FROM : Daniel Child
DATE : Thu May 15 05:54:12 2008
I think I understood the first half of what you said, and can now see
why making number the receiver of addObserver was totally wrong.
But I seem to have a problem.
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. In other
words, your "myFoo addObserver: self <THE CONTROLLER> forKeyPath:
@"number" becomes....
- (void) awakeFromNib {
[self addOberver: self forKeyPath: @"number" options: 0 context: NULL];
}
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.
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.
On May 14, 2008, at 5:11 PM, Ken Thomases wrote:
> To illustrate:
>
> @interface Foo : NSObject
> {
> NSNumber* number; // <-- This is NOT the property
> }
>
> // _These_ are the property:
> - (NSNumber*) number;
> - (void) setNumber:(NSNumber*)newNumber;
>
> @end
>
>
> // ... in some other code somewhere
>
> Foo* myFoo = /* ... */
> [myFoo addObserver:self forKeyPath:@"number"];
>
> This object (self) is observing the myFoo object for changes in its
> "number" property.
>
>
> Think also about the KVO notifications you will receive:
>
> - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:
> (id)object change:(NSDictionary *)change context:(void *)context;
DATE : Thu May 15 05:54:12 2008
I think I understood the first half of what you said, and can now see
why making number the receiver of addObserver was totally wrong.
But I seem to have a problem.
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. In other
words, your "myFoo addObserver: self <THE CONTROLLER> forKeyPath:
@"number" becomes....
- (void) awakeFromNib {
[self addOberver: self forKeyPath: @"number" options: 0 context: NULL];
}
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.
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.
On May 14, 2008, at 5:11 PM, Ken Thomases wrote:
> To illustrate:
>
> @interface Foo : NSObject
> {
> NSNumber* number; // <-- This is NOT the property
> }
>
> // _These_ are the property:
> - (NSNumber*) number;
> - (void) setNumber:(NSNumber*)newNumber;
>
> @end
>
>
> // ... in some other code somewhere
>
> Foo* myFoo = /* ... */
> [myFoo addObserver:self forKeyPath:@"number"];
>
> This object (self) is observing the myFoo object for changes in its
> "number" property.
>
>
> Think also about the KVO notifications you will receive:
>
> - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:
> (id)object change:(NSDictionary *)change context:(void *)context;
| Related mails | Author | Date |
|---|---|---|
| Daniel Child | May 14, 21:08 | |
| Ken Thomases | May 14, 23:11 | |
| Daniel Child | May 15, 05:54 | |
| Ken Thomases | May 15, 06:09 | |
| Daniel Child | May 15, 06:43 | |
| Ken Thomases | May 15, 06:54 | |
| Daniel Child | May 16, 04:47 | |
| Ken Thomases | May 16, 05:33 |






Cocoa mail archive

