我有一个显示两分钟的视图(启动画面):
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[viewController showSplash];
}
- (void)showSplash // Show splash screen
{
UIViewController *modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[self performSelector:@selector(hideSplash) withObject:nil afterDelay:120.0];
}
我想在这个初始屏幕上添加一个从 2 分钟倒计时到零的计时器。
我想我需要创建另一个包含计时器的视图。这个对吗?我将如何执行此操作并将其添加到启动屏幕,以及如何使计时器中的数字以白色显示在屏幕上?
我知道两分钟显示启动画面的时间很长……但我只是在尝试各种事情,这两分钟还有其他事情发生!
非常感谢,
斯图
编辑 // 好的,我现在有了这个:
(。H)
NSTimer *timer5;
UILabel *countDown;
float timeOnSplash;
(.m)
- (void) updateLabel:(NSTimer*)theTimer
{
float timeOnSplash = timeOnSplash - 1;
countDown.text = [NSString stringWithFormat:@"%02d:%02d", timeOnSplash];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
timer5 = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateLabel:)
userInfo:nil
repeats:YES];
countDown.text = [NSString stringWithFormat:@"%02d:%02d", timeOnSplash];
}
运行代码时出现以下未捕获的异常:
'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:此类不符合键 countDown 的键值编码。
有任何想法吗?
编辑 2 // 现在工作,有关出色的解决方案,请参阅 TechZen 的答案。
非常感谢大家!