drawRect not getting called when needed under OS X
I am using a window that uses a subclass of NSView. Part of it is drawn when the program starts, another part needs to be drawn when the user clicks on a button in another window. The code for the other window calls my subclass of NSView with no problems, creates the new graphics, and then returns. However, the window that needs to get updated with new graphics does not change.
When I put both the beginning graphics and the graphics that are to be drawn later in the initial drawRect call everything is drawn without a problem. However, drawRect does not get called when the user clicks the button on the second window. I've tried awakeFromNib, setNeedsDisplay, needsDisplay, and display, but nothing I've found so far gets the NSView window to call drawRect.
I am f开发者_如何学Goairly new to OS X programming and appreciate any hints you can throw my way.
Thanks, Tom Jeffries
You should separate button click into a controller class and that controller should call setNeedsDisplay on view object. Don't say view itself setNeedsDisplay.
精彩评论