在 OS X 下,当需要时,drawRect 不会被调用
我正在使用一个使用 NSView 子类的窗口。其中一部分在程序启动时绘制,另一部分需要在用户单击另一个窗口中的按钮时绘制。另一个窗口的代码毫无问题地调用我的 NSView 子类,创建新图形,然后返回。但是,需要用新图形更新的窗口不会改变。
当我将开始图形和稍后要绘制的图形都放在初始drawRect调用中时,所有内容都绘制没有问题。但是,当用户单击第二个窗口上的按钮时,不会调用drawRect。我已经尝试过 awakeFromNib、setNeedsDisplay、needsDisplay 和 display,但到目前为止我还没有发现任何能让 NSView 窗口调用 drawRect 的方法。
我对 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 fairly new to OS X programming and appreciate any hints you can throw my way.
Thanks, Tom Jeffries
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将按钮单击单独放入控制器类中,并且该控制器应该在视图对象上调用 setNeedsDisplay。不要说视图本身setNeedsDisplay。
You should separate button click into a controller class and that controller should call setNeedsDisplay on view object. Don't say view itself setNeedsDisplay.