Xcode NSTimer在停止时显示UILabel和UIImageView
在我的应用程序项目中,我希望能够点击一个按钮,等待5秒钟,然后出现UILabel和UIImageView。以下是我目前掌握的情况:Xcode NSTimer在停止时显示UILabel和UIImageView,xcode,uiimageview,uibutton,uilabel,nstimer,Xcode,Uiimageview,Uibutton,Uilabel,Nstimer,在我的应用程序项目中,我希望能够点击一个按钮,等待5秒钟,然后出现UILabel和UIImageView。以下是我目前掌握的情况: - (IBAction)startTimer { responseBox.placeholder = @"Message Here"; timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerStop) userInfo:nil r
- (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;
}
}
一切都链接正确,发生了什么事?
mainit
只在按下startTimer
按钮时递增,因此在timerStop
中没有任何好处。另外,如果要正确地递增mainit
,请使用mainit++代码>
试试这个:
- (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;
}
谢谢,它现在可以工作了。我在大约一小时前自己纠正了这个问题,但是你的代码可能是最好的方法。谢谢在现已过时的
mainit
上用后期增量替换+=1
有什么意义?还有,为什么计时器还在重复?你怎么知道mainit
没有在课堂上的其他地方使用?如果用户不希望计时器重复,则可以更改该选项。