这个问题在这里已经有了答案:
Why does viewWillAppear not get called when an app comes back from the background?
(7 个回答)
4年前关闭。
我有以下 Storyboard。有一个OrderViewController
当我第一次打开应用程序时,它会调用 -(void) viewWillAppear: (BOOL) animated
方法,但是当我打开另一个应用程序(将此应用程序置于后台),然后再次返回此应用程序时,viewWillAppear
方法不再被调用?
最佳答案
您发送了viewWillAppear
当您的 View 添加到窗口的 View 层次结构时的消息。
当应用程序从后台移动到前台时,窗口的 View 层次结构不会改变,因此不会为该事件发送消息。
如果您想知道(在您的 View Controller 中)您的应用程序何时进入前台,您应该监听 UIApplicationWillEnterForeground
通知或 UIApplicationWillBecomeActive
通知(或两者),具体取决于您的确切需求。
阅读 “Strategies for Handling App State Transitions” in the App Programming Guide for iOS有关何时发送这些通知的更多信息。
关于ios - viewWillAppear 只被调用一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45534639/