【发布时间】:2013-07-20 16:46:22
【问题描述】:
这不是所有的代码。我已经确保我已经正确声明了所有内容,但是标签没有随着“秒”的减少而改变。
我不知道为什么在 'subtractTime' 中我已经使 timerLabel.text 等于字符串,格式使用秒数“应该”并且在我使用警报重置游戏时倒计时,所以即使标签没有改变,我知道它正在倒计时,否则不会从等于 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
【问题讨论】:
-
如果您在 IB 中创建了
timerLabel,它是否连接正确? -
IBOutlet UILabel *scoreLabel; IBOutlet UILabel *timerLabel; NSInteger 计数; NSInteger 秒; NSTimer *timer;
-
您是否在 Interface Builder 中建立了连接?
-
在subtractTime方法之后你多了一个
;。 -
我不确定,因为我是一个非常新手的 obj-c 程序员。什么是界面生成器?
标签: objective-c