NSTimer help...

Discussion in 'Mac Programming' started by ledd, Dec 21, 2007.

  1. ledd macrumors newbie

    Joined:
    Dec 26, 2006
    #1
    So I have an application that I have developed in a NSDocument. I want to be able to have it do an update on a timer which I think understand how to implement.

    The only problem is I am not familiar with where the NSTimer function would be continuously called every lets say 1 second?

    I have a MyDocument.m file which contains my UpdateUI function which is what I would want the NSTimer to call.

    And then I also have my main.h file which simply has

    Code:
    #import <Cocoa/Cocoa.h>
    
    int main(int argc, char *argv[])
    {
        return NSApplicationMain(argc, (const char **) argv);
    }
    
    Thanks.
     
  2. ledd thread starter macrumors newbie

    Joined:
    Dec 26, 2006
    #2
    I apologize for the unnecessary thread I figured it out.

    Awesomely enough for those who don't know you can just start the timer from any function call. I don't really know why I thought this would not work. I guess I thought there was maybe a standard that should be upheld to where you should make the NSTimer.
     
  3. ledd thread starter macrumors newbie

    Joined:
    Dec 26, 2006
    #3
    I've run into another minor issue that I am struggling with.
    So I have a button that I want to change the text of when it is clicked....

    So I have...
    NSButton* calculate;

    So I figured I could do...
    [calculate setTitle: @"New Title"];

    But this didn't appear to work. Did I do something wrong?
    Thanks.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    How is the button created? Is it an IBOutlet connected in Interface Builder?
     
  5. ledd thread starter macrumors newbie

    Joined:
    Dec 26, 2006
    #5
    Yah its an IBOutlet NSButton and then the calculate functions is an IBAction that is connected to the NSButton
     
  6. Nutter macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #6
    Could you post a bit more code? What does your complete -calculate: method look like?
     
  7. ledd thread starter macrumors newbie

    Joined:
    Dec 26, 2006
    #7
    Ok... lets see if I can appropriately map this out

    I have a button in my window... In the InterfaceBuilder I have declared an IBOutlet for the button called stopStartBtn in the Inspector
    In my .h I have

    Code:
    IBOutlet NSButton* stopStartBtn
    
    and a method

    Code:
    - (IBAction)startStopCounter:(id) sender;
    
    The startStopCounter method is as follows

    Code:
    - (IBAction)startStopCounter:(id)sender
    {	
    	if(timer == nil){
    		[self startTimer];
    		[startStopBtn setTitle: @"Pause"];
    	}
    	else{
    		[self stopTimer];
    		[startStopBtn setTitle: @"Start"];
    	}
    }
    
    The functions startTimer and stopTimer work great but the setTitle change does not create a change...

    Hope this outlines the issue better. Thanks.
     
  8. ledd thread starter macrumors newbie

    Joined:
    Dec 26, 2006
    #8
    I got it it. It was a bad connection with the .nib file.

    Thanks.
     

Share This Page