setNeedsDisplay 不起作用?
我在简单的可可应用程序中重绘自定义视图时遇到问题。 绘图基于一个由简单的 NSSlider 更改的参数。 然而,尽管我实现了 -setParameter: 和 -parameter 方法并将滑块的值绑定到界面生成器中的该参数,但我似乎无法创建自定义视图来重绘自身。
进行重绘的代码如下:
- (void)setParameter:(int)newParameter {
parameter = newParamter;
NSLog(@"Updated parameter: %d", parameter);
[self setNeedsDisplay:YES];
}
尽管视图本身不会重绘,但我确实收到了有关设置新参数的消息。 欢迎任何想法!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常的语法是:
[self setNeedsDisplay:YES]
,尽管我认为这意味着同样的事情。 您是在实现- (void)drawRect:(NSRect)rect
方法,还是使用超类的drawRect:
方法?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 thedrawRect:
method of your superclass?对于在使用
NSOpenGLView
子类时遇到此问题的任何人,您可能会忘记在drawRect:[[self openGLContext]lushBuffer]
代码>.For anyone that has this problem while using an
NSOpenGLView
subclass, you might be forgetting to use[[self openGLContext] flushBuffer]
at the end ofdrawRect:
.有时原因可能非常简单:文件的所有者与 UIView 对象没有连接。 即它的插座设置不正确。
使用IB、ctrl按钮和拖动方法:)
Sometimes reason can be very simple: File's owner has no connection to UIView object. i.e. it's Outlet is not setup properly.
Use IB, ctrl button and drag method :)
在 iOS 6 中,没有这样的函数可以调用:
setNeedsDisplay:YES
。 我遇到了同样的问题,并提出了以下解决方案: https://stackoverflow.com/a/15027374/1280800 .希望它会有所帮助。
In the iOS 6 there isn't such function to call:
setNeedsDisplay:YES
. I've got the same problem, and came with this solution: https://stackoverflow.com/a/15027374/1280800 .Hope it will help.