This problem has been frustrating me for a while now. I was determined to figure it out without help. But I'm thinking now either I'm just plain dumb, or it's a dumb mistake I'm not seeing. A while back I asked about selectors. I didn't understand a word people were saying. But now, having read the Apple Objective-C documentation, especially the one pertaining to selectors, and after doing some small tests, I thought I could fix my problem. But I can't.
So the situation:
Here's all four class files (two classes total).
I know from my logs that everything works fine until it gets to incrementInt. incrementInt gets called, but that's as far as it goes. draw doesn't get called. I'm proud of myself because I identified a possible problem... when I call animateIntVariable: ... I pass self as an argument for receiver. The problem is, I don't know what else to put there if that is wrong. If it's not the problem, I'm completely stumped.
Thanks for all your help so far!
Nate
So the situation:
Here's all four class files (two classes total).
Code:
#import <Cocoa/Cocoa.h>
#import "ESAnimation.h"
@interface AppController : NSObject {
IBOutlet id field;
ESAnimation *animate;
}
- (IBAction)button:(id)sender;
- (void)draw;
@end
Code:
#import "AppController.h"
@implementation AppController
- (IBAction)button:(id)sender {
NSLog(@"button pressed");
animate=[[ESAnimation alloc] init];
[animate animateIntVariable:1 toValue:1 atSpeed:1.0 inIncrementsOf:1 receiver:self selector:@selector(draw)];
}
- (void)draw {
NSLog(@"draw invoked");
[field setStringValue:@"success!"];
}
@end
Code:
#import <Cocoa/Cocoa.h>
@interface ESAnimation : NSObject {
id userObject;
SEL userSelector;
NSTimer *timer;
}
- (void)animateIntVariable:(int)aVariable toValue:(int)aValue atSpeed:(float)aSpeed inIncrementsOf:(int)anIncrement receiver:(id)aReceiver selector:(SEL)aSelector;
- (void)incrementInt:(NSTimer *)aTimer;
@end
Code:
#import "ESAnimation.h"
@implementation ESAnimation
- (void)animateIntVariable:(int)aVariable toValue:(int)aValue atSpeed:(float)aSpeed inIncrementsOf:(int)anIncrement receiver:(id)userObject selector:(SEL)userSelector {
NSLog(@"animateIntVariable invoked");
[self incrementInt:nil];
}
- (void)incrementInt:(NSTimer *)aTimer {
NSLog(@"incrementInt invoked");
[userObject performSelector:userSelector];
}
@end
I know from my logs that everything works fine until it gets to incrementInt. incrementInt gets called, but that's as far as it goes. draw doesn't get called. I'm proud of myself because I identified a possible problem... when I call animateIntVariable: ... I pass self as an argument for receiver. The problem is, I don't know what else to put there if that is wrong. If it's not the problem, I'm completely stumped.
Thanks for all your help so far!
Nate