mouse event

Discussion in 'Mac Programming' started by stece, Oct 30, 2008.

  1. stece Guest

    Joined:
    Oct 9, 2008
    #1
    Dear all
    I have a code like this:

    Code:
    #import <Cocoa/Cocoa.h>
    
    
    @interface Clasa : NSObject {
    	IBOutlet NSTextField *textField;
    }
    -(IBAction)seed:(id)sender;
    -(IBAction)generate:(id)sender;
    @end
    ---------------------------------------------
    #import "Clasa.h"
    
    
    @implementation Clasa
    - (IBAction)generate:(id)sender
    {
    	int generated;
    	generated = (random()% 100) + 1;
    	NSLog(@"generated = %d", generated);
    	[textField setIntValue:generated];
    }
    - (IBAction)seed:(id)sender
    {
    	srandom(time(NULL));
    	[textField setStringValue:@"Generator seeded"];
    }
    
    @end
    and how does the computer know that if I push the button it is to
    show the int generated. I mean how does he know it in the function of time ( namely how does he know when to do it) because there is no mouseclick event defined or anything similar. So which event punctuates it and how?
    I read there are some actions, but how do these actions refer to the mouse click or push of the button?

    Thank you in advance
     
  2. SydneyDev macrumors 6502

    Joined:
    Sep 15, 2008
    #2
    The button object stores in it's member variables a pointer to another object, and the name of a method to call on that object when it is clicked.

    In Interface Builder, you create an instance of your object (above) and drag a line from the button to your object to set these member variables. The settings you make here are saved in the Interface Builder XIB file and restored at runtime.
     
  3. stece thread starter Guest

    Joined:
    Oct 9, 2008
    #3
    About using Apple documantation

    How to know from reference library of the NSButton which member variables are pointers to another object, and how to know which method they call if I click the button ?
     
  4. SydneyDev macrumors 6502

    Joined:
    Sep 15, 2008
    #4

Share This Page