当 iPhone 上的 applicationDidBecomeActive 时,如何从活动实例设置 NSTimer 的目标
我在 appDelegate 中创建了一个 NSTimer 来处理应用程序锁定或放入后台时的暂停,但计时器选择器位于另一个 viewController 中,当用户位于该 viewController 中然后单击主页按钮时,应用程序将关闭并移动到后台,但是当点击应用程序时,我需要在 applicationDidBecomeActive 中再次设置计时器,但不确定如何从应用程序委托访问活动 viewController,我尝试在viewController 的 viewDidAppear 但它没有被解雇,如果有人有一些关于如何处理这个问题的线索,我将非常感激。
I have an NSTimer that I created in the appDelegate to handle the pause when the app locks or is put in the background, but the timers selector is in another viewController, when the user is in that viewController and then hits the home button the app closes and moves to the background, but when the app is tapped I need to set the timer again, in the applicationDidBecomeActive, but am not sure how I access the active viewController from the app delegate, I have tried setting the timer in the viewController's viewDidAppear but it is not fired, if anyone has some clues as how to handle this I would be very grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,事实证明这很简单,我只是没有考虑清楚,可能有点太累了,无论如何答案与 David 提到的很接近,关键是循环遍历导航控制器中的 viewControllers 来获取正确的视图控制器
Well it turns out that this is pretty easy, I just wasn't thinking it through, maybe a bit too tired, anyway the answer is close to what David mentioned, the key is to loop through the viewControllers in the navigation controller to get the proper viewController
创建一个变量来在应用程序委托中存储 viewController...
或者,如果您使用的是 UINavigationController,则可以使用 [navigationController topViewController]
Create a variable to store viewController in the app delegate...
Or if you are using a UINavigationController you can use [navigationController topViewController]