My problem is that when the action UpdateRect calls the drawRect method, my rect doesn’t update the height!
When I click on the button, I expect to see my rect height to 20 but it remains to 10. Why?
@implementation Graphic_view
int height = 10; //The height of my rect.
-(IBAction)updateRect:(id)sender {
height += 10;
//Calling the drawrect method
[self performSelector:@selector(drawRect:)];
}
-(void)drawRect:(NSRect)dirtyRect {
NSLog(@"DrawRect has been called !");
// Drawing code here.
NSRect viewBounds = [self bounds];
NSColor *color = [NSColor orangeColor];
[colore set];
NSRectFill(viewBounds);
NSRect myRect;
myRect.origin.x = 20;
myRect.origin.y = 20;
myRect.size.height = height;
myRect.size.width = 100;
NSColor *whiteColor = [NSColor whiteColor];
[whiteColor set];
NSRectFill(myRect);
}
@end
You should never call
drawRect:yourself. Instead callsetNeedsDisplay:Note: The iOS equivalent is
setNeedsDisplaywithout an argument.