liptonlover
Jul 27, 2008, 10:59 PM
I'm trying to learn how to get a timer working... I read the apple docs on timers and loops. I also went through the loop and nstimer class docs. Finally I went through the chapter on NSTimer in cocoa programming for mac os x. Here's my unsuccessful code. (I just checked, all my connections are good. As far as I can tell it should work. Pressing "go" does nothing though...)
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject/* Specify a superclass (eg: NSObject or NSView) */ {
IBOutlet id progressBar;
NSTimer *timer;
int count;
}
- (IBAction)go:(id)sender;
- (IBAction)reset:(id)sender;
- (IBAction)stop:(id)sender;
@end
#import "AppController.h"
@implementation AppController
- (IBAction)go:(id)sender {
timer=[[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(increment:) userInfo:nil repeats:YES] retain];
}
- (IBAction)reset:(id)sender {
}
- (IBAction)stop:(id)sender {
}
- (void)increment:(NSTimer *)aTimer {
count=count+1;
[progressBar setIntValue:count];
}
@end
Can anyone tell me what's wrong? Thanks! Nate
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject/* Specify a superclass (eg: NSObject or NSView) */ {
IBOutlet id progressBar;
NSTimer *timer;
int count;
}
- (IBAction)go:(id)sender;
- (IBAction)reset:(id)sender;
- (IBAction)stop:(id)sender;
@end
#import "AppController.h"
@implementation AppController
- (IBAction)go:(id)sender {
timer=[[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(increment:) userInfo:nil repeats:YES] retain];
}
- (IBAction)reset:(id)sender {
}
- (IBAction)stop:(id)sender {
}
- (void)increment:(NSTimer *)aTimer {
count=count+1;
[progressBar setIntValue:count];
}
@end
Can anyone tell me what's wrong? Thanks! Nate
