0

So I'm having an issue drawing a custom view inside my existing window. I have a custom class called GraphView that I use to draw a graph of values onto the view. The graph gets passed variables each second and should get redrawn via setNeedsDisplay:YES. I can get this same class to work in a standalone xCode project, but in order for this to work, I have to control-drag from the custom view in Interface Builder to the File's Owner, and the view will redraw. All of the draw code works correctly in the standalone xCode project so I know my drawRect method, and all of the other view methods work the way I intend them to. I can also get this GraphView to work in my current project if I do the same thing, but applicationDidFinishLaunching will not run.

Here's a breakdown of the code in the sample project.

@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

What is the part that I'm missing so that I don't have to make the connection in InterfaceBuilder from my GraphView to File's Owner to get the view to update with [self.graph setNeedsDisplay:YES]. Any help or direction would be appreciated.

1 Answers1

0

If your GraphView is loaded by Interface Builder, you don't need to allocate it in your code. Be sure in IB to indicate the good class name.

An other thing, if you really want to alloc init your GraphView in your code and don't use IB, don't forget to addSubview: it in your window.

mastohhh
  • 561
  • 6
  • 5