gpt4 book ai didi

ios - UITabBar Lifecycle 的方法不会从后台启动

转载 作者:行者123 更新时间:2023-11-28 07:26:56 26 4
gpt4 key购买 nike

我有一个 UITabBar Controller 作为主 Controller ,有 2 个选项卡。每个选项卡都是一个嵌入了 UIViewControllerNavigatorViewController

如果我在上一次冷启动后从后台打开应用程序,ViewWillAppear(UITabBarControllerUIViewController)都不会被触发。

当用户来自后台时,如何调用UITabBarChildren的生命周期? (IE:来自通知)

最佳答案

这不在生命周期中,因为 Controller 的状态在后台模式或其他应用程序事件期间不会改变。

您应该观察 applicationWillEnterForegroundNotification

class VC: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Listen for application event somewhere early like `ViewDidLoad`
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForegroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)
}

// Implement a function that you want to execute when event happen
@objc func applicationWillEnterForegroundNotification() {
// Do anything before application Enter Foreground
}

// Remove observer when the controller is going to remove to prevent further issues
deinit {
NotificationCenter.default.removeObserver(self)
}
}

关于ios - UITabBar Lifecycle 的方法不会从后台启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56324942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com