UILabel 未显示正确的数据,因为它为零
我有一个 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];
}
}
I have a uilabel, and it is not displaying the correct text because it is nil. How can I stop the label from being nil? Thanks
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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很糟糕的问题,而且代码格式也越来越糟糕,但我会冒险猜测您没有在 nib 文件中正确连接 UILabel 插座。
另外,您“点击”的 IBAction 签名错误。
That's poorly asked question, and ever more poorly formatted code, but I'm going to hazard the guess that you have not properly connected the UILabel outlet in your nib file.
Also, your IBAction "tapped" has the wrong signature.