views:

3688

answers:

2

Hi all!

I have a problem redrawing a custom view in simple cocoa application. Drawing is based on one parameter that is being changed by a simple NSSlider. However, although i implement -setParameter: and -parameter methods and bind slider's value to that parameter in interface builder i cannot seem to make a custom view to redraw itself.

The code that does redrawing is like this:

- (void)setParameter:(int)newParameter {
  parameter = newParamter;
  NSLog(@"Updated parameter: %d", parameter);
  [self setNeedsDisplay:YES];
}

I DO get the message about setting the new parameter although the view doesn't redraw itself. Any ideas are welcome!

+3  A: 

The usual syntax is: [self setNeedsDisplay:YES], although I would assume that that means the same thing. Are you implementing the - (void)drawRect:(NSRect)rect method, or using the drawRect: method of your superclass?

e.James
thanks for pointing out typo with true/YESI implement my own drawRect: method
Eimantas
if you put an NSLog(@"hi") at the top of your DrawRect: method, does it get called?
e.James
no, it doesn't get called. it gets called only once on program startup
Eimantas
hmmm. Based on the information given so far, I'm stumped. Is there anything out of the ordinary about your setup?
e.James
does this thread help at all? http://www.idevgames.com/forum/archive/index.php/t-10114.html
e.James
thanks, will check that one out
Eimantas
Let me know what works. I'm curious now!
e.James
well i worked it out in a different way.i removed setter and getter methods and changed them with one IBAction in custom view class that updates instance variable and calls setNeedsDisplay. Works like a charm.I guess i need more homework with KVC/KVO theory.Thanks again, eJames!
Eimantas
I didn't do much. Glad it worked out!
e.James
A: 

For anyone that has this problem while using an NSOpenGLView subclass, you might be forgetting to use [[self openGLContext] flushBuffer] at the end of drawRect:.

Eric