ViewDidAppear 主页按钮

发布于 2025-01-01 00:17:08 字数 280 浏览 0 评论 0原文

我有一个带倒计时的计时器。在最近的测试中,我注意到,如果我点击主页按钮并返回应用程序,计时器就会关闭(计时的秒数比应有的秒数要少)。

我在测试中注意到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾冷 2025-01-08 00:17:08

您可能需要 applicationDidBecomeActive:applicationWillResignActive:,它们会发送到您的应用程序委托。您还可以收听已发布的通知(例如UIApplicationDidBecomeActiveNotification)。

例如,当出现系统警报时,也会发布这些信息。如果您只想在进入后台时被告知,请尝试 applicationDidEnterBackground:applicationWillEnterForeground:

请参阅有关生命周期的 Apple 文档了解详细信息。

You probably want applicationDidBecomeActive: and applicationWillResignActive:, 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: and applicationWillEnterForeground:

See the Apple Docs on lifecycle for details.

心如荒岛 2025-01-08 00:17:08

只是为了跟进,正如上面回答的问题一样。

我遇到了与 Eric 完全相同的问题,然后我实现了 Jesse 关于在委托上使用 applicationDidBecomeActive: 的建议。我只是想确定如何调用所有不同的方法,我发现:

  1. application:didFinishLaunchingWithOptions: 正如预期的那样,从一开始就被调用。
  2. 然后,轮到主视图控制器的viewDidLoad了。
  3. 然后调用viewWillAppear:
  4. 回到应用程序委托中,applicationDidBecomeActive: 被触发(这里我调用我在主视图控制器中实现的reactivateTimer 方法)。
  5. 执行reactivateTimer方法。
  6. 最后一步是调用主视图控制器的 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:

  1. application:didFinishLaunchingWithOptions: is called at the very start, as expected.
  2. Then, is the main view controller's viewDidLoad turn.
  3. Then viewWillAppear: is called.
  4. Back in the application delegate, applicationDidBecomeActive: is triggered (here I call my reactivateTimer method which I implemented in the main view controller).
  5. The reactivateTimer method is executed.
  6. The last step is the call to the main view controller's viewDidAppear:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文