gpt4 book ai didi

ios - 秒表故障

转载 作者:行者123 更新时间:2023-11-29 11:11:29 25 4
gpt4 key购买 nike

我最近做了一个秒表应用程序,它有一些小故障。

如果我连续两次点击停止按钮,整个应用程序就会崩溃。

如果我连续按两次开始按钮,计时器将以两倍的速度运行,而停止按钮将停止工作。

我该如何解决这个问题?

这是我的 .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

这是我在 .m 文件中的代码:

- (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;
if (newTime == 60) {
newTime = 0;
}
time.text = [NSString stringWithFormat:@"%d", newTime];
}

- (void)showActivity1 {
int currentTime1 = [time1.text intValue];
int newTime1 = currentTime1 + 1;
if (newTime1 == 10) {
newTime1 = 0;
}
time1.text = [NSString stringWithFormat:@"%d", newTime1];
}

- (void)showActivity2 {
int currentTime2 = [time2.text intValue];
int newTime2 = currentTime2 + 1;
time2.text = [NSString stringWithFormat:@"%d", newTime2];
}

最佳答案

-stop 方法时,将停止按钮的 userInterActionEnabled 属性设置为 NO 并将开始按钮的属性设置为 YES被解雇了。然后切换并将停止按钮的 userInterActionEnabled 设置为 YES,并在触发 -start 时将开始按钮设置为 NO

关于ios - 秒表故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11384803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com