FROM : Graham Cox
DATE : Fri May 02 16:44:29 2008
You also need to override -respondsToSelector: and return a logical OR
of your delegate plus the old delegate's response, something like:
- (BOOL) respondsToSelector:(SEL) aSelector
{
BOOL responds = [super respondsToSelector:aSelector];
if( !responds )
responds = [[self oldDelegate] respondsToSelector:aSelector];
return responds;
}
Also, forwardInvocation isn't called unless your object has already
rejected the message, so its implementation should look like:
- (void) forwardInvocation:(NSInvocation*) invocation
{
SEL aSelector = [invocation selector];
if ([[self oldDelegate] respondsToSelector:aSelector])
[invocation invokeWithTarget:[self controller]];
else
[self doesNotRecognizeSelector:aSelector];
}
hth,
G.
On 3 May 2008, at 12:35 am, Matthew Gertner wrote:
> Hi,
>
> I am implementing an application delegate for a framework (Mozilla)
> that already registers its own delegate internally. Ideally I would
> like to be able to handle specific delegate messages in my class (in
> this case adding items to the dock tile menu) and forward all other
> invocations to the old delegate. So before I call [[NSApplication
> sharedApplication] setDelegate] for my delegate, I retrieve the
> existing delegate and save it in a member variable (mOldDelegate). I
> thought that I could get invocations to forward automatically like
> this:
>
> - (void)forwardInvocation:(NSInvocation *)anInvocation
> {
> if ([mOldDelegate respondsToSelector:[anInvocation selector]])
> [anInvocation invokeWithTarget:mOldDelegate];
> else
> [super forwardInvocation:anInvocation];
> }
>
> - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
> {
> if ([mOldDelegate respondsToSelector:aSelector])
> return [mOldDelegate methodSignatureForSelector:aSelector];
> else
> return [super methodSignatureForSelector: aSelector];
> }
>
> For some reason neither methodSignatureForSelector nor
> forwardInvocation is ever called. Perhaps this has something to do
> with the way messages are sent to the delegate by the application. As
> a result, my delegate never forwards to the old delegate. Any guidance
> would be appreciated.
>
> Matt
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/graham.<email_removed>
>
> This email sent to graham.<email_removed>
DATE : Fri May 02 16:44:29 2008
You also need to override -respondsToSelector: and return a logical OR
of your delegate plus the old delegate's response, something like:
- (BOOL) respondsToSelector:(SEL) aSelector
{
BOOL responds = [super respondsToSelector:aSelector];
if( !responds )
responds = [[self oldDelegate] respondsToSelector:aSelector];
return responds;
}
Also, forwardInvocation isn't called unless your object has already
rejected the message, so its implementation should look like:
- (void) forwardInvocation:(NSInvocation*) invocation
{
SEL aSelector = [invocation selector];
if ([[self oldDelegate] respondsToSelector:aSelector])
[invocation invokeWithTarget:[self controller]];
else
[self doesNotRecognizeSelector:aSelector];
}
hth,
G.
On 3 May 2008, at 12:35 am, Matthew Gertner wrote:
> Hi,
>
> I am implementing an application delegate for a framework (Mozilla)
> that already registers its own delegate internally. Ideally I would
> like to be able to handle specific delegate messages in my class (in
> this case adding items to the dock tile menu) and forward all other
> invocations to the old delegate. So before I call [[NSApplication
> sharedApplication] setDelegate] for my delegate, I retrieve the
> existing delegate and save it in a member variable (mOldDelegate). I
> thought that I could get invocations to forward automatically like
> this:
>
> - (void)forwardInvocation:(NSInvocation *)anInvocation
> {
> if ([mOldDelegate respondsToSelector:[anInvocation selector]])
> [anInvocation invokeWithTarget:mOldDelegate];
> else
> [super forwardInvocation:anInvocation];
> }
>
> - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
> {
> if ([mOldDelegate respondsToSelector:aSelector])
> return [mOldDelegate methodSignatureForSelector:aSelector];
> else
> return [super methodSignatureForSelector: aSelector];
> }
>
> For some reason neither methodSignatureForSelector nor
> forwardInvocation is ever called. Perhaps this has something to do
> with the way messages are sent to the delegate by the application. As
> a result, my delegate never forwards to the old delegate. Any guidance
> would be appreciated.
>
> Matt
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/graham.<email_removed>
>
> This email sent to graham.<email_removed>
| Related mails | Author | Date |
|---|---|---|
| Matthew Gertner | May 2, 16:35 | |
| Graham Cox | May 2, 16:44 | |
| Andy Lee | May 2, 16:53 | |
| Andy Lee | May 2, 16:55 | |
| Matthew Gertner | May 2, 16:55 | |
| Matthew Gertner | May 2, 16:56 | |
| Bill Cheeseman | May 2, 17:04 | |
| Graham Cox | May 2, 17:18 |






Cocoa mail archive

