Re: propblems w/ outline view delegate and notifications
Re: propblems w/ outline view delegate and notifications
- Subject: Re: propblems w/ outline view delegate and notifications
- From: Corbin Dunn <email@hidden>
- Date: Thu, 20 Nov 2008 14:57:08 -0800
Le Nov 20, 2008 à 1:42 PM, email@hidden a écrit :
given the following sequence of events:
1) load a window (NSWindow subclass) from a nib using an
NSWindowController subclass
2) the window contains an NSOutlineView, and the delegate of the
outline view is the window
3) in the window's awakeFromNib call:
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(gotTableColSizeChanged:)
name: NSOutlineViewColumnDidResizeNotification
object: outline];
4) later on in awakeFromNib, set the outline's delegate to nil
i've discovered, via breakpoints in the debugger and via the fact
that my notification selector isn't called, that step 4 is removing
my observer!
and while now that i know this is happening, its been easy enough to
work around, but i'm wondering if this is expected behavior? and if
so, is it documented anywhere? if not, can anyone comment as to
whether or not it is a bug (personally, i think it probably is, but
i could be talked out of this). i will report this via radar if
appropriate.
Ah, the answer is yes, it is expected, and yes, it should be
documented (please log a bug requesting that it be documented - you
can reference this email and the content I give here).
In short, when you call setDelegate:, the delegate is automatically
registered for the following notifications:
APPKIT_EXTERN NSString *NSTableViewSelectionDidChangeNotification;
APPKIT_EXTERN NSString *NSTableViewColumnDidMoveNotification; //
@"NSOldColumn", @"NSNewColumn"
APPKIT_EXTERN NSString *NSTableViewColumnDidResizeNotification; //
@"NSTableColumn", @"NSOldWidth"
APPKIT_EXTERN NSString *NSTableViewSelectionIsChangingNotification;
with the following callback selectors (declared in the NSTableView
informal delegate protocol):
- (void)tableViewSelectionDidChange:(NSNotification *)notification;
- (void)tableViewColumnDidMove:(NSNotification *)notification;
- (void)tableViewColumnDidResize:(NSNotification *)notification;
- (void)tableViewSelectionIsChanging:(NSNotification *)notification;
So, calling setDelegate:nil will undo that registration, which happens
to undo the one you did since a registration goes by observer/name/
object and does not key off of the selector (if it did, you would have
seen -removeObserver:selector:name:object: --- but, this method does
not exist).
Short answer: use -tableViewColumnDidResize instead.
corbin_______________________________________________
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