ViewDidAppear 主页按钮
我有一个带倒计时的计时器。在最近的测试中,我注意到,如果我点击主页按钮并返回应用程序,计时器就会关闭(计时的秒数比应有的秒数要少)。
我在测试中注意到 ViewDid 和 ViewWill Appear 在重新打开应用程序时不会触发。我知道:
- (void)applicationWillEnterForeground:(UIApplication *)application
火灾,但是如何使其特定于处于活动状态的 viewController 的某些部分?
I have a timer with a countdown. In recent testing, I've noticed that if I hit the home button and return to the app, the timer is off (fewer seconds have ticked off than should).
I've noticed in testing that ViewDid and ViewWill Appear do not fire when re-opening the app. I know that:
- (void)applicationWillEnterForeground:(UIApplication *)application
Fires, but how do I make it specific to certain part of a viewController that was active?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要
applicationDidBecomeActive:
和applicationWillResignActive:
,它们会发送到您的应用程序委托。您还可以收听已发布的通知(例如UIApplicationDidBecomeActiveNotification
)。例如,当出现系统警报时,也会发布这些信息。如果您只想在进入后台时被告知,请尝试
applicationDidEnterBackground:
和applicationWillEnterForeground:
请参阅有关生命周期的 Apple 文档了解详细信息。
You probably want
applicationDidBecomeActive:
andapplicationWillResignActive:
, which are sent to your app delegate. There are also notifications posted (e.g.UIApplicationDidBecomeActiveNotification
) you could listen for.Those are also posted when, e.g., a system alert comes in. If you just want to be told when you're going to the background, try
applicationDidEnterBackground:
andapplicationWillEnterForeground:
See the Apple Docs on lifecycle for details.
只是为了跟进,正如上面回答的问题一样。
我遇到了与 Eric 完全相同的问题,然后我实现了 Jesse 关于在委托上使用
applicationDidBecomeActive:
的建议。我只是想确定如何调用所有不同的方法,我发现:application:didFinishLaunchingWithOptions:
正如预期的那样,从一开始就被调用。viewDidLoad
了。viewWillAppear:
。applicationDidBecomeActive:
被触发(这里我调用我在主视图控制器中实现的reactivateTimer
方法)。reactivateTimer
方法。viewDidAppear:
Just for the sake of follow up, as the question was answered above.
I had the exact same problem as Eric and then I implemented Jesse's suggestion about using
applicationDidBecomeActive:
on the delegate. I just wanted to make sure how all the different methods were being called, and I found this:application:didFinishLaunchingWithOptions:
is called at the very start, as expected.viewDidLoad
turn.viewWillAppear:
is called.applicationDidBecomeActive:
is triggered (here I call myreactivateTimer
method which I implemented in the main view controller).reactivateTimer
method is executed.viewDidAppear: