• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]


  • Subject: Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
  • From: Conrad Shultz <email@hidden>
  • Date: Mon, 25 Mar 2013 13:54:40 -0700

On Mar 25, 2013, at 12:47 PM, Chris Tracewell <email@hidden> 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 (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

  • Follow-Ups:
    • Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
      • From: Chris Tracewell <email@hidden>
References: 
 >Custom Delegate - Using _delegate works but not delegate or [self delegate] (From: Chris Tracewell <email@hidden>)

  • Prev by Date: Re: [indexPath row] uncaught exception
  • Next by Date: Re: Pop Up Menu in NSTableView
  • Previous by thread: Custom Delegate - Using _delegate works but not delegate or [self delegate]
  • Next by thread: Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
  • Index(es):
    • Date
    • Thread