It is sometimes needed for a UIView subclass to register as an NSNotificationCenter observer. However, there seems to be no good place for adding/removing NSNotificationCenter observers… The best place, I have found so far, is in willMoveToWindow: and didMoveToWindow methods.
Just add observers in didMoveToWindow and remove them in willMoveToWindow!
– is called immediately after its window property gets set.
– is called before the view is added to to a window. It also will be called when the view is removed from its window. The newWindow property will be nil then. That’s why a check that newWindow is nil needs to be performed (it indicates that the view was just removed).