我有一个stopclock应用程序,并希望startCountButton
按钮在最初按下时被禁用,然后stopCountButton
按下按钮使其再次启用,以便只能按下一次启动按钮.这是我的代码
- (IBAction)startCount:(UIButton*)sender { countInt = 0; self.label.text = [NSString stringWithFormat:@"%i", countInt]; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countTimer) userInfo:nil repeats:YES]; } - (IBAction)stopCount:(UIButton*)sender { countInt = 0; [timer invalidate]; } -(void)countTimer { countInt += 1; self.label.text = [NSString stringWithFormat:@"%i", countInt]; }
我需要添加什么帮助?我不打算改变文本,只是禁用它
首先,您需要对按钮的引用.然后,将以下代码添加到startCount:
:
((UIButton *)sender).enabled = NO
并stopCount:
补充:
startCountButton.enabled = YES