Best way to deinit Initial view controller?

情到浓时终转凉″ 提交于 2019-12-11 04:24:51

问题


I have a loading view controller when my app starts(is is my initial view controller).When an animation in this view controller finished I want it to show another view controller and dismiss the view controller with the animation.

The loading view controller is the initial view controller,

I have this code when UIStoryboard.mflMainTabBarViewController(). returns the view controller that I want to present

func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
    let animationID = anim.value(forKey: "animationID")
    if animationID as! NSString == "transform" {
        self.present(UIStoryboard.mflMainTabBarViewController(), animated: true, completion: {
            _ = self.popoverPresentationController
        })

    }
}

But when deinit is never called

deinit {
print("deinit")

} What is the best way to deinit the first view controller, and making the presenting view controller the root view controller?


回答1:


Unless you're doing something very specialized, you don't need to de-init an object in Swift. It will be called automatically when the reference count goes to 0. If you really need to, you should be able to set you window's rootViewController through your AppDelegate.

However, be aware that maintenance like this is rarely necessary.




回答2:


A deinitializer is called immediately before a class instance is deallocated

after you can use

    if let delegate = UIApplication.shared.delegate as? AppDelegate {

        let storyboard : UIStoryboard? = UIStoryboard(name: "storyboardName", bundle: nil)
        let rootController = storyboard!.instantiateViewController(withIdentifier: "controllerIdentifier")

        delegate.window?.rootViewController = rootController
    }


来源:https://stackoverflow.com/questions/45601121/best-way-to-deinit-initial-view-controller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!