现在我真的很沮丧,搜索整个互联网,偶然发现,仍然没有找到解决方案。NSTimer不会调用方法
我想实现一个NSTimer,但我定义的方法没有被调用。 (秒设置正确,用断点检查它)。下面是代码:
- (void) setTimerForAlarm:(Alarm *)alarm {
NSTimeInterval seconds = [[alarm alarmDate] timeIntervalSinceNow];
theTimer = [NSTimer timerWithTimeInterval:seconds
target:self
selector:@selector(showAlarm:)
userInfo:alarm repeats:NO];
}
- (void) showAlarm:(Alarm *)alarm {
NSLog(@"Alarm: %@", [alarm alarmText]);
}
对象 “theTimer” 是deined与@property:
@interface FooAppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate> {
@private
NSTimer *theTimer;
}
@property (nonatomic, retain) NSTimer *theTimer;
- (void) setTimerForAlarm:(Alarm *)alarm;
- (void) showAlarm:(Alarm *)alarm;
我在做什么错?
'showAlarm:(Alarm *)alarm'的方法签名应该是'showAlarm:(NSTimer *)timer'。然后,您将得到具有Alarm * alarm = [timer userInfo]'的Alarm对象。 – 0xced 2011-05-20 18:49:04
谢谢,已经得到了;-) – tamasgal 2011-05-20 22:19:57