Objective c 秒表圈
我正在使用Xcode 4作为单视图应用程序进行停止监视。。不过我有个问题。当毫秒计数时,它们会向内移动。我希望他们达到9,然后在0重新开始。我还希望秒数达到59,然后回到0。 以下是我的viewcontroller.m文件中的代码:Objective c 秒表圈,objective-c,stopwatch,Objective C,Stopwatch,我正在使用Xcode 4作为单视图应用程序进行停止监视。。不过我有个问题。当毫秒计数时,它们会向内移动。我希望他们达到9,然后在0重新开始。我还希望秒数达到59,然后回到0。 以下是我的viewcontroller.m文件中的代码: - (IBAction)start{ myTicker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showActivity) userInfo:ni
- (IBAction)start{
myTicker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
myTicker2 = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(showActivity1) userInfo:nil repeats:YES];
myTicker3 = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(showActivity2) userInfo:nil repeats:YES];
}
- (IBAction)stop{
[myTicker invalidate];
[myTicker2 invalidate];
[myTicker3 invalidate];
}
- (IBAction)reset{
time.text = @"00";
time1.text = @"00";
time2.text = @"00";
}
- (void)showActivity{
int currentTime = [time.text intValue];
int newTime = currentTime + 1;
time.text = [NSString stringWithFormat:@"%d", newTime];
}
- (void)showActivity1{
int currentTime1 = [time1.text intValue];
int newTime1 = currentTime1 + 1;
time1.text = [NSString stringWithFormat:@"%d", newTime1];
}
- (void)showActivity2{
int currentTime2 = [time2.text intValue];
int newTime2 = currentTime2 = 1;
time2.text = [NSString stringWithFormat:@"%d", newTime2];
}
这是我在.h文件中的代码
IBOutlet UILabel *time;
IBOutlet UILabel *time1;
IBOutlet UILabel *time2;
NSTimer *myTicker;
NSTimer *myTicker2;
NSTimer *myTicker3;
}
- (IBAction)start;
- (IBAction)stop;
- (IBAction)reset;
- (void)showActivity;
- (void)showActivity1;
- (void)showActivity2;
@end
任何关于如何做到这一点的答案都将不胜感激。谢谢 在您的情况下,我只使用1个计时器(一个计数毫秒)和4个int变量(小时、分钟、秒和毫秒)。然后在计时器上打勾,你就可以测试了
if (milliseconds > 999)
{
seconds++;
milliseconds = 0;
}
if (seconds > 59)
{
minutes++;
seconds = 0;
}
if (minutes > 59)
{
hours++;
minutes = 0;
}
因此,通过这样做,您有一个计时器来管理所有变量。我快速编写了这段代码,所以可能有拼写错误