取消初始化初始视图控制器的最佳方法? [英] Best way to deinit Initial view controller?

查看: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,

当我有UIStoryboard.mflMainTabBarViewController()时,我有此代码.返回我要呈现的视图控制器

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
        })

    }
}

但是当从未调用deinit时

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?

推荐答案

在取消分配类实例之前立即调用反初始化器

A deinitializer is called immediately before a class instance is deallocated

使用后

    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
    }

这篇关于取消初始化初始视图控制器的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆