Skip navigation.
 
mlBest place to remove observer for NSViewBoundsDidChangeNotification
FROM : Jonathan Dann
DATE : Mon Feb 25 23:15:29 2008

Hi Guys,

I have a document-based non-GC app in which I register my document 
instance to receive an NSViewBoundsDidChangeNotification for my 
[[mainTextView enclosingScrollView] contentView].

On dealloc, the document calls [[NSNotificationCenter defaultCenter] 
removeObserver:self], but these notifications still get sent to the 
dealloc'd instance when the window itself closes.  I think this is 
something to do with the notification being sent/received in a delayed 
manner, am I right?

I've now overridden NSDocument's -close method to remove self from 
observing these notifications before calling [super close] (which 
works fine) but I was wondering if there was a better, more 
conventional place to put these -removeObserver: calls.  I'm not sure 
if this makes sense but are there any view-related methods that get 
called when a document/window closes that would be the best place to 
de-register for observations of view notifications? Could what I've 
done bite me if, for example, for some reason -close does not get 
called?

Thanks,

Jon

Related mailsAuthorDate
mlBest place to remove observer for NSViewBoundsDidChangeNotification Jonathan Dann Feb 25, 23:15
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification Jerry Krinock Feb 26, 00:15
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification Jonathan Dann Feb 26, 00:30
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification Jonathan Dann Mar 4, 19:29