PDA

View Full Version : How to repaint 'drawRect' in custom view?




youngplayer
Jul 3, 2008, 02:49 AM
In my opinion, the 'drawRect' function seems like the 'paint' function in java.
So, is there some some function like 'repaint' which refresh the screen?

For example,
-(void) drawRect: (NSRect) rect{
NSString * str = [otherObject stringToDisplay];
[str drawAtPoint: originalPoint withAttributes: attributes];
}

How can I refresh the screen immediately when the value of [otherObject stringToDisplay] has been changed?



robbieduncan
Jul 3, 2008, 03:48 AM
You tell the view that it need redrawing via the setNeedsDisplay: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/setNeedsDisplay:) method clearly highlighted in the documentation.