0

This is not all the code. I have made sure that I have declared everything correctly however the label is not changing as 'seconds' is decreasing.

I'm not sure why as in 'subtractTime' I have made timerLabel.text equal to the string with format using seconds which "should" and is counting down as I use an alert to reset the game and so even though the label isn't changing, I know it is counting down otherwise the alert wouldn't be triggered from 'seconds' equalling 0.

- (void)setupGame;
{
    seconds = 30;
    count = 0;

    timerLabel.text = [NSString stringWithFormat: @"Time: %i", seconds];
    scoreLabel.text = [NSString stringWithFormat: @"Score: %i", count];

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0
         target:self
         selector:@selector(subtractTime)
         userInfo:nil
         repeats:YES];

}
- (void)subtractTime;
{
    seconds--;
    timerLabel.text = [NSString stringWithFormat:@"Time: %i", seconds];

    if (seconds == 0)
    {
        [timer invalidate];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Time is up !" 
                          message: [NSString stringWithFormat: @"You Scored %i points", count]
                          delegate:self
                          cancelButtonTitle: @"Play Again"
                          otherButtonTitles:nil];

        [alert show];
    }

}
@end
4

1 回答 1

0

确保在 Storyboard/Interface builder 中,您的标签已正确连接到 viewXontroller 的 .h 文件。测试这一点的一个好方法是在 XIB 上用“时间:”以外的东西“启动”你的标签,而是用像“foo”这样无意义的东西。这样一来,您就可以准确判断标签是否发生了变化,而不是排除您的 Int 值是否显示不正确。

于 2013-07-20T16:56:40.740 回答