• 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: Quincey Morris <email@hidden>
  • Date: Tue, 26 Mar 2013 12:38:50 -0700

On Mar 26, 2013, at 10:30 , Chris Tracewell <email@hidden> wrote:

> How can I get [self delegate] to recognize my custom methods?

There are two ways, one simpleminded, the other a bit sophisticated:

1. Use a local variable:

	id<TKOutlineViewDelegate> delegate = [self delegate];
	…
	[delegate  outlineView:self enterKeyPressedForRow:[self selectedRow]];
	…

You'd need to introduce the local variable into each scope where you send the delegate one of your custom messages.

2. Redeclare the "delegate" property:

	@interface TKOutlineView : NSOutlineView {}
	@property (nonatomic,readonly) id<TKOutlineViewDelegate> delegate;
	@end

	@implementation TKOutlineView
	@dynamic delegate;
	…
	[[self delegate]  outlineView:self enterKeyPressedForRow:[self selectedRow]];
	…

The @dynamic statement says "I don't have an implementation of the 'delegate' property in this class, but that's just fine because it's already implemented (in my superclass)".

Alternatively, you can avoid @dynamic by supplying an overriding implementation:

	- (id<TKOutlineViewDelegate>) delegate {
		return [super delegate];
	}

but the @dynamic version is a bit more elegant.

With either alternative, this approach lets you avoid the clutter of the additional local variables.

_______________________________________________

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>
    • 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>)
 >Re: Custom Delegate - Using _delegate works but not delegate or [self delegate] (From: Conrad Shultz <email@hidden>)
 >Re: Custom Delegate - Using _delegate works but not delegate or [self delegate] (From: Chris Tracewell <email@hidden>)
 >Re: Custom Delegate - Using _delegate works but not delegate or [self delegate] (From: Conrad Shultz <email@hidden>)
 >Re: Custom Delegate - Using _delegate works but not delegate or [self delegate] (From: Chris Tracewell <email@hidden>)

  • Prev by Date: Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
  • Next by Date: Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
  • Previous by thread: Re: 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