开发者

drawRect not getting called when needed under OS X

开发者 https://www.devze.com 2023-03-22 06:45 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号