November 06, 2004

NSViews, timers, and visibility

I'm running into a stumbling block with Cocoa, and after spending an hour searching through documentation and not finding an answer I figure I'll post it here and see if anyone reading this knows the answer. Bear in mind that I'm unfortunately not much of a Cocoa programmer.

I have a custom view (a subclass of NSView) with a timer that updates something in the view. The view only needs to be updated when it's visible, and it's visible whenever its window is visible. How do I stop the timer when its window is hidden or closed and start the timer again when the window is shown?