UILabel没有显示正确的数据,因为它是零

时间:2011-01-07 19:07:20

标签: objective-c ios4 uilabel int

我有一个uilabel,它没有显示正确的文本,因为它是零。如何阻止标签为零?谢谢 用mkdev

- (IBAction)tapped
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:kTimerOn] == NO) {
        originalCountdownTime = 10;
        countdownTime = originalCountdownTime;
        [timeLeft setText:[NSString stringWithFormat:@"%d", countdownTime]];
        countdownTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownOneSecond) userInfo:nil repeats:YES] retain];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kTimerOn];
    }
    [self setTapAmount:tapAmount];
}



- (void)setTapAmount:(UILabel *)label
{
    ++numberOfTaps;
    NSString *countString = [NSString stringWithFormat:@"%d", numberOfTaps];
    [label setText:countString];
    NSLog(@"%@", countString);
}
- (void)countDownOneSecond
{
    int newTime = --countdownTime;
    timeLeft.text = [NSString stringWithFormat:@"%d", newTime];
    if (countdownTime == 0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations" message:[NSString stringWithFormat:@"You Tapped %i times in %i seconds!", numberOfTaps, originalCountdownTime] delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Try Again", @"View Local Leaderboard",nil];
        [alert show];
        [alert release];
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kTimerOn];
        [countdownTimer invalidate];
    }
}

1 个答案:

答案 0 :(得分:0)

这是一个问题很少的问题,而且格式化的代码质量也很差,但是我会冒这样的猜测:你没有正确连接你的nib文件中的UILabel插座。

此外,您的IBAction“tapped”签名错误。