问题
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