Re: Add KVO for observing center property from a UIImageView
Re: Add KVO for observing center property from a UIImageView
- Subject: Re: Add KVO for observing center property from a UIImageView
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 23 Jun 2011 17:36:18 -0600
On Jun 23, 2011, at 5:27 PM, Tales Pinheiro de Andrade wrote:
> Hi again.
>
> I have a custom view (say ECGlassView), subclass from UIImageView, and this view has a subview (say ECNeedleView) that is subclass from UIImageView.
>
> I'm trying to add viewA as observer for viewB center, as I can move viewB above viewA. When I try to tho this:
>
>
> [self.needle addObserver:self forKeyPath:@"needle.center" options:NSKeyValueObservingOptionNew context:@"needleCenter"];
>
> the program abort, with the message:
>
> *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ECNeedleView 0x8b1cf30> addObserver:<ECGlassView 0x8b1bac0> forKeyPath:@"needle.center" options:0x1 context:0x21eec] was sent to an object that is not KVC-compliant for the "needle" property.'
>
> In ECGlassView.h I have:
>
> @interface ECGlassView : UIImageView {
> ECNeedleView *needle;
> }
> @property (nonatomic, assign) ECNeedleView *needle;
> @end
>
> And have synthesized needle property in ECGlassView.m file.
>
> Even if I try to declare center property in ECNeedleView.h and synthesize it, it doesn't work.
>
> What I'm doing wrong?
The program is attempting to make the object's "needle" value observe the key path "needle.center", meaning the key path it's trying to observe looks like self.needle.needle.center from the perspective of your ECGlassView object. Unless your ECNeedleView has a property also called needle, then that won't work (and if it did, then it would observe the wrong object). If you drop the "needle" from the key path, then it'll probably work.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
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