Is there some sort of delegate method that sends a message when an NSView is being shown or not? I need to run an NSTimer when the NSView is displayed on the screen and I need to invalidate it when it is not so it doesn't unnecessarily run in the background the whole time.
Asked
Active
Viewed 284 times
1 Answers
0
Depending on how you've implemented your code, you could subclass NSView and create your own delegate protocol that sends out proper messages for various NSView events like setHidden
or "removeFromSuperview
".
If you're embedding this view into a single NSWindow object, you could subclass NSWindow and then throw your custom delegate protocol methods for "close
" or "performClose:
". Of course, in this case, there's actually already a "NSWindowDelegate
" protocol defined for you.

Michael Dautermann
- 88,797
- 17
- 166
- 215
-
Thanks for your answer but could you perhaps be more specific how I could make use of `setHidden` so that it behaves like a delegate method? – iMaddin Jul 03 '12 at 08:18
-
will your NSView be appearing in only one NSWindow object or could it appear in one of many different unique windows? – Michael Dautermann Jul 03 '12 at 13:10
-
How about detecting when a UITableViewCell is offscreen and then cancelling the timer? [Other people have asked this question before](http://stackoverflow.com/questions/841042/detect-when-uitableviewcell-goes-off-the-screen). – Michael Dautermann Jul 05 '12 at 05:26
-
There is nothing in that post that has helped me. I did find this delegate method `- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex` but I haven't been able to get it work right now. But I need a `willHideCell` version of this. – iMaddin Jul 10 '12 at 02:39