Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITabBar生命周期';的方法不会从后台启动_Ios_Swift_Cocoa Touch_Uitabbar - Fatal编程技术网

Ios UITabBar生命周期';的方法不会从后台启动

Ios UITabBar生命周期';的方法不会从后台启动,ios,swift,cocoa-touch,uitabbar,Ios,Swift,Cocoa Touch,Uitabbar,我有一个uitabar控制器作为主控制器,有两个选项卡。每个选项卡都是一个NavigatorViewController,其中嵌入了UIViewController 如果在上一次冷启动后从后台打开应用程序,则不会出现视图(UITabBarController,UIViewController) 当用户来自后台时,我如何调用uitabarchildren的生命周期?(即:来自通知)当应用程序来自后台时,对于任何活动的vc调用非viewWillDisplay/viewDidDisplay,您需要收听

我有一个
uitabar
控制器作为主控制器,有两个选项卡。每个选项卡都是一个
NavigatorViewController
,其中嵌入了
UIViewController

如果在上一次冷启动后从后台打开应用程序,则不会出现
视图
UITabBarController
UIViewController


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

当应用程序来自后台时,对于任何活动的vc调用非
viewWillDisplay/viewDidDisplay
,您需要收听应用程序委托,如
applicationWillEnterForegroundNotification

NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForegroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)
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)
    }
}


这不在生命周期中,因为在后台模式或其他应用程序事件期间,控制器的状态没有改变

您应该遵守
applicationWillEnterForegroundNotification

NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForegroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)
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)
    }
}

您可以在
控制器中向
UIApplicationWillEnterForeground
添加一个
观察者

在某个应用程序离开后台状态前往 成为活跃的应用程序


当您导航到其他屏幕时,不要忘记删除观察器。