Intercepting and forwarding delegate messages
Intercepting and forwarding delegate messages
- Subject: Intercepting and forwarding delegate messages
- From: Steven Spencer <email@hidden>
- Date: Sat, 16 Jul 2005 00:02:19 +0100
Hello,
I'm writing a NSTableView subclass to automatically handle variable
row heights.
I've set the subclass as the superclass delegate so I can intercept
the following delegate methods :
- (void)tableViewColumnDidResize:(NSNotification *)aNotification
- (void)tableView:(NSTableView *)tableView didClickTableColumn:
(NSTableColumn *)tableColumn
- (float)tableView:(NSTableView *)tableView heightOfRow:(int)row
I would like my subclass to have it's own delegate so I can forward
the unhandled superclass delegate methods to my subclass's delegate.
The subclass has an instance variable for cached row heights and its
own delegate instance variable mDelegate, accessed through the
overridden accessor :
- (void)setDelegate:(id)anObject;
{
mDelegate = anObject;
}
- (id)delegate;
{
return mDelegate;
}
Unfortunately, the above "get" delegate method is called by the
superclass repeatedly, rather than the superclass using its own
instance variable. This causes messages to be sent to the wrong
delegate.
For example when the subclass's delegate hasn't been set (is nil),
the tableView:heightOfRow: message is sent to nil, rather than the
originally set superclass delegate.
This workaround prevents the messages being sent to nil, but causes
the subclass to return the wrong delegate :
- (id)delegate;
{
return [super delegate];
}
Maybe there's a better way of intercepting and forwarding delegate
messages.
I hope someone can provide some enlightenment.
Thanks for your time.
- Steve Spencer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden