在我的app项目中,我希望能够点击一个按钮,等待5秒钟,然后出现UILabel和UIImageView。这是我到目前为止所做的:
- (IBAction)startTimer
{
responseBox.placeholder = @"Message Here";
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerStop) userInfo:nil repeats:YES];
mainInt +=1;
}
- (void)timerStop
{
if (mainInt == 5)
{
[timer invalidate];
titleLabel.hidden = NO;
messageLabel.hidden = NO;
messageLabel.text = @"Message";
image.hidden = NO;
}
}
一切都正确联系,发生了什么?
答案 0 :(得分:1)
mainInt
只有在您按下startTimer
按钮时才会递增,这样您就无法timerStop
。另外,如果您想正确增加mainInt
,请使用 mainInt++;
试试这个:
- (IBAction)startTimer
{
responseBox.placeholder = @"Message Here";
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerStop) userInfo:nil repeats:YES];
mainInt++;
}
- (void)timerStop
{
[timer invalidate];
titleLabel.hidden = NO;
messageLabel.hidden = NO;
messageLabel.text = @"Message";
image.hidden = NO;
}