嗨,我基本上是在使用 NSTimer 制作一个简单的计时器。
我有代码来记住开始日期(NSDate),然后每秒触发一个重复计时器以更新界面。我发现计时器正确触发并调用了选择器,但在第一行出现异常。任何帮助深表感谢。
遗漏了无关位的代码:
#import <Foundation/Foundation.h>
@interface PPTTimer : NSObject
{
NSTimer *mainTimer;
NSDate *startTime;
NSTimeInterval timerDuration;
NSTimer *clockTimer;
NSTimer *safariTimer;
}
- (void)startTimerForHours:(int)hours minutes:(int)mins;
- (void)pauseTimer;
- (void)resumeTimer;
- (void)finishTimer;
- (void)endTimer:(NSTimer *)theTimer;
- (void)updateClockFire:(NSTimer *)theTimer;
- (void)safariCheckFire:(NSTimer *)theTimer;
@property (assign) IBOutlet NSTextField *leftField;
@property (assign) IBOutlet NSTextField *rightField;
@property (assign) IBOutlet NSTextField *leftLabel;
@property (assign) IBOutlet NSTextField *rightLabel;
@end
#import "PPTTimer.h"
@implementation PPTTimer
@synthesize leftField = leftField_;
@synthesize rightField = rightField_;
- (void)startTimerForHours:(int)hours minutes:(int)mins
{
startTime = [NSDate date];
timerDuration = 60*(mins+60*hours);
mainTimer = [NSTimer scheduledTimerWithTimeInterval:timerDuration target:self selector:@selector(endTimer:) userInfo:nil repeats:NO];
clockTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateClockFire:) userInfo:nil repeats:YES];
safariTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(safariCheckFire:) userInfo:nil repeats:YES];
}
选择器代码,错误截图:
这是(相关部分)AS 代码,请记住 PPTTimer 有一个蓝色立方体,它与缺失值相关联……</p>
property parent : class "NSObject"
--app classes
property PPTTimer : missing value
--windows
property winMain : missing value
property winTimer : missing value
--IB objects
property hourField : missing value
property minuteField : missing value
on startTimerButton_(sender)
winMain's orderOut_(sender)
winTimer's makeKeyAndOrderFront_(sender)
PPTTimer's startTimerForHours_minutes_(hourField's intValue(), minuteField's intValue())
end startTimerButton_