【发布时间】:2018-06-12 14:54:42
【问题描述】:
我有一个FakeSplashController,它执行一些网络请求,然后打开WelcomeViewController。当我在WelcomeViewController 中查看内存图时,我看到SplashViewController 仍然在那里。我在FakeSplashController 中调用deinit 函数来检查它是否正在拒绝但它没有调用它。可能是什么问题?
我在WelcomeViewController 时在内存中看到的内容:
FakeSplashController:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupUI()
networkRequests()
}
func networkRequests(){
AppInitService().initAppRequest { [](result) in
switch result{
case .success(_):
self.startAnimation()
return
case .error(let error):
UIControlUtil.showErrorMessage(title: error.title, message: error.message, closeButton: true)
return
}
}
}
func openApp(){
let loginController = WelcomeViewController()
self.present(loginController, animated: true)
}
func startAnimation(){
UIView.animate(withDuration: 0.8, animations: {
self.logoImage.frame.origin.x -= 100
}, completion: nil)
UIView.animate(withDuration: 1,delay: 0.3,animations: {
self.textLogo.alpha = 1
self.textLogo.frame.origin.x += 50
}, completion: { _ in
self.openApp()
})
}
deinit {
print("Splash Deinited")
}
编辑:正如我在下面的帖子中提到的那样,有人提到了这一点;
除非您正在做一些非常专业的事情,否则您不需要在 Swift 中取消初始化对象。它会在引用计数变为 0 时自动调用。如果确实需要,您应该可以通过 AppDelegate 设置窗口的 rootViewController。
所以我不需要把它当作一个问题吗? Best way to deinit Initial view controller?
【问题讨论】:
-
自从您提出
WelcomeViewController后,您希望如何释放启动画面? -
我想我不确定是否需要。因为我和splash没有任何关系了。
-
一个视图控制器在你展示另一个视图控制器时不会被释放;它仍然生活在新的之下。事实上,如果你关闭
WelcomeViewController,你会再次看到飞溅 -
@RicoCrescenzio 是对的,你也可以看到,当你打开 Xcode 的 ViewDebugger 时。在 ViewDebugger 中向两侧滚动一点,您将看到,在 WelcomeViewController 后面是 SplashViewController。当您关闭 WelcomeViewController 时,您也会看到 SplashViewController。
标签: ios swift uiviewcontroller