tags:

views:

79

answers:

1

I think this is a very simple question, but I’m new to programming so I may be going about it in a wrong-headed way.

I have a basic understanding of Objective-C writing terminal applications and am teaching myself how to use the Cocoa GUI.

I understand how to use IBOutlet and IBAction to connect a simple button to a method that will repeatedly send random numbers to a textfield.

I understand how to add a NSView file, connect it to a custom view in interface builder and draw a path through random points in the view when the application launches.

(I’ve been putting this code inside the - (void)drawRect:(NSRect)dirtyRect method that is declared when the file is created).

What I can’t seem to figure out is how to connect a button to an action that will then ‘refresh’ the view – in this case repopulate it with another set of random points connected with a path. Looking at the documentation, I think I should somehow be using

– (void) setNeedsDisplay(BOOL)flag 

but nothing I have tried so far had worked. Please tell me, what am I missing here?

+1  A: 

Something like this:

- (IBAction)refreshButtonAction:(id)sender
{
    [theView setNeedsDisplay:YES];
}

Connect your button to that action. "theView" is a reference to your custom NSView.

macatomy
Thank you! I had tried similar things, but I wasn't declaring my custom NSView as an instance variable in the AppController. Then I tried to add the button into the NSView and send [self setNeedsDisplay:YES];silly newbie :)
Josan