views:

126

answers:

4

I have multiple custom NSViews in my Cocoa program. I am looking for a way to force them to invalidate without having to add additional code while the program is running. If I were doing this with on Windows with the .NET framework, I would just drag part of my program offscreen and drag back on again. Areas that was offscreen get invalidated when they come back on screen. I haven't figure out how to do this with Cocoa - OSX.

+3  A: 

The methods setNeedsDisplay should do it:

- (void)setNeedsDisplay:(BOOL)flag
- (void)setNeedsDisplayInRect:(NSRect)invalidRect

Docs here

pgb
My question was not clear. I want to cause invalidation while the program is running.
phi
Are you looking to invalidate them via user action, or code?
Ben Gottlieb
+1  A: 

Windows on Mac OS X are buffered by the Window Server and can't be forced to redraw by moving them around the screen. The only way the user can force a redraw is to resize the window.

Why do you need to do this, though?

Rob Keniger
A: 

I recommend you try F-script http://www.fscript.org/. It allows you to call methods on Cocoa objects while your program is running.

You could use it to call the setNeedsDisplay:(BOOL)flag or setNeedsDisplayInRect:(NSRect)invalidRect methods directly on the view you would like to invalidate.

Ira Cooke
A: 

Minimize the window and unminimize it. That happens to force a redraw.

Ken