【发布时间】:2014-07-21 15:26:23
【问题描述】:
所以我在现有窗口中绘制自定义视图时遇到了问题。我有一个名为GraphView 的自定义类,我用它在视图上绘制值图。该图每秒都会获得传递的变量,并且应该通过setNeedsDisplay:YES 重新绘制。我可以让这个相同的类在一个独立的 xCode 项目中工作,但为了让它工作,我必须从 Interface Builder 中的自定义视图控制拖动到File's Owner,并且视图将重绘。所有的绘制代码在独立的 xCode 项目中都能正常工作,所以我知道我的 drawRect 方法,并且所有其他视图方法都按照我想要的方式工作。如果我做同样的事情,我也可以让这个GraphView 在我当前的项目中工作,但applicationDidFinishLaunching 不会运行。
以下是示例项目中的代码细分。
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// This code does not run when I drag the custom view's referencing outlet to File's Owner in IB
self.graph = [[GraphView alloc]init];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
-(IBAction)firstPoint:(id)sender{
[self.graph addNewPoint:[self.textValue floatValue]];
[self.graph setNeedsDisplay:YES];
}
@end
我缺少什么部分,这样我就不必在 InterfaceBuilder 中从我的GraphView 连接到File's Owner 以使用[self.graph setNeedsDisplay:YES] 更新视图。任何帮助或指导将不胜感激。
【问题讨论】:
标签: objective-c xcode nsview custom-view setneedsdisplay