ios - viewWillAppear 只被调用一次

标签 ios cocoa-touch uiviewcontroller

这个问题在这里已经有了答案:





Why does viewWillAppear not get called when an app comes back from the background?

(7 个回答)


4年前关闭。




我有以下 Storyboard。有一个OrderViewController当我第一次打开应用程序时,它会调用 -(void) viewWillAppear: (BOOL) animated方法,但是当我打开另一个应用程序(将此应用程序置于后台),然后再次返回此应用程序时,viewWillAppear方法不再被调用?

enter image description here

最佳答案

您发送了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/

相关文章:

objective-c - 问题: Parsing XML File in Objective-C/Cocoa Project for iOS

ios - 查看 Controller 未被释放

javascript - 类型错误 : undefined is not an object only in Safari and iOS

iphone - vuforia 和 uinavigationcontroller

objective-c - UITableView 提交编辑错误

objective-c - 新的自动引用计数机制是如何工作的?

iphone - 在另一个类中设置标签文本

ios - 在 xib 文件中加载 View Controller

iphone - AVAssetExportSession estimatedOutputFileLength 总是返回 0

iphone - addSubview 修改添加的 View 的框架