View Full Version : NSTimer help...
ledd
Dec 22, 2007, 12:33 AM
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
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
Thanks.
ledd
Dec 22, 2007, 12:49 AM
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.
ledd
Dec 22, 2007, 01:46 AM
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.
kainjow
Dec 22, 2007, 03:26 AM
How is the button created? Is it an IBOutlet connected in Interface Builder?
ledd
Dec 22, 2007, 09:15 AM
Yah its an IBOutlet NSButton and then the calculate functions is an IBAction that is connected to the NSButton
Nutter
Dec 23, 2007, 05:54 AM
Could you post a bit more code? What does your complete -calculate: method look like?
ledd
Dec 23, 2007, 12:13 PM
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
IBOutlet NSButton* stopStartBtn
and a method
- (IBAction)startStopCounter:(id) sender;
The startStopCounter method is as follows
- (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.
ledd
Dec 23, 2007, 01:01 PM
I got it it. It was a bad connection with the .nib file.
Thanks.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.