Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode NSTimer在停止时显示UILabel和UIImageView_Xcode_Uiimageview_Uibutton_Uilabel_Nstimer - Fatal编程技术网

Xcode NSTimer在停止时显示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

在我的应用程序项目中,我希望能够点击一个按钮,等待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;
    }
}

一切都链接正确,发生了什么事?

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
没有在课堂上的其他地方使用?如果用户不希望计时器重复,则可以更改该选项。