On Mar 25, 2013, at 12:47 PM, Chris Tracewell <ch...@thinkcl.com> wrote:

> I have a subclass of NSOutlineView that has custom delegate methods. In the 
> implementation file I get an error for "No known instance method for 
> selector..." when I call these declared methods using [self delegate] or 
> delegate. However the compiler suggested using _delegate and that makes the 
> error go away. I thought since my subclass inherits from NSOutlineView that 
> delegate would be recognized and available.

"[self delegate]" is not the same as "delegate" - the former sends the 
-delegate message, the latter references a variable named "delegate" (which the 
compiler is telling you does not exist).

> -(void)keyDown:(NSEvent *)theEvent
>       {
>       if ([[theEvent characters] length] == 0)
>               {
>               // dead key
>               return;
>               }
>       else if ([[theEvent characters] length] == 1 && [[theEvent characters] 
> characterAtIndex:0] == NSEnterCharacter && [[self delegate] 
> respondsToSelector:@selector(outlineView: enterKeyPressedForRow:)]) 
>               {
>               [delegate outlineView:self enterKeyPressedForRow:[self 
> selectedRow]];

For example, here you correctly use "[self delegate]" in the if() condition but 
improperly fall back to merely "delegate" for actually dispatching your 
delegate message.

> Is _delegate the correct usage here or have I done something else wrong? 
> Thank you.

The correct usage is [self delegate] in place of just "delegate." You could 
also create a local variable assigned to [self delegate] if you wish.

-Conrad
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to