为什么我的计时器可以在 iPad 模拟器上运行,但不能在 iPad 上运行?
我正在使用所有 UIKit,并且出于原型设计的目的,我刚刚将所有逻辑推入主视图控制器中。我在 viewDidLoad 中创建一些 UIView,隐藏一些,然后设置一个 NStimer 在 4 秒内取消隐藏隐藏的。该计时器在模拟器中完美触发,但在 iPad 上永远不会触发。为什么会发生这种情况以及我应该寻找什么?
这是我设置视图和计时器的地方。
- (void)viewDidLoad {
[super viewDidLoad];
//snipped out long code that adds UIViews as subviews and runs fine
curtainView.hidden=YES;
questionLabel.hidden=YES;
[NSTimer scheduledTimerWithTimeInterval:4
target:self
selector:@selector(dropCurtain:)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(askQuestion:)
userInfo:nil
repeats:NO];
这
是第一个计时器到时时调用的函数。这不能在 iPad 上运行。
-(void)dropCurtain:(NSTimer *)timer{
curtainView.hidden=NO;
//curtainView.alpha=.5;
[self.view bringSubviewToFront:curtainView];
[self.view bringSubviewToFront:triesLabel];
}
I'm working with all UIKit, and—for prototyping purposes have just shoved all the logic into the main viewController. I create some UIViews in viewDidLoad, hide some, and then set an NStimer to unhide the hidden ones in 4 seconds. This timer fires perfectly in the simulator, but will never fire on the iPad. Why could this happen and what should I even be looking for?
This is where I set my view and timer.
- (void)viewDidLoad {
[super viewDidLoad];
//snipped out long code that adds UIViews as subviews and runs fine
curtainView.hidden=YES;
questionLabel.hidden=YES;
[NSTimer scheduledTimerWithTimeInterval:4
target:self
selector:@selector(dropCurtain:)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(askQuestion:)
userInfo:nil
repeats:NO];
}
And here's the function that gets called when the first timer is up. This doesn't run on the iPad.
-(void)dropCurtain:(NSTimer *)timer{
curtainView.hidden=NO;
//curtainView.alpha=.5;
[self.view bringSubviewToFront:curtainView];
[self.view bringSubviewToFront:triesLabel];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的回调可能不在主线程中被调用,ui 更改调用仅适用于主线程。如果是这种情况,有一个 nsobject 的方法可以在主线程中安排对选择器的调用,您可以从回调中调用它来操作 ui
(抱歉,不在我的工作计算机附近)
Your callback might be called not in the main thread, ui changes call only works from the main thread. If this is the case there's a method of nsobject to schedule a call to selector in the main thread, and you can call this from your callback to manipulate ui
(sorry not near my work computer)