我正在尝试在Playground测试中测试是否释放了我的视图控制器。在我的应用中,我希望有一个外部控制器,该控制器将导航控制器作为子级呈现,而另一个视图控制器作为子级,而我的解雇代码直接位于子级中,该子级应先升至导航控制器,然后向sideMenu
传播。控制器。但是没有一个控制器变为零。就实例而言,据我所知,我没有控制器的其他参考。我想念什么?
import UIKit
import PlaygroundSupport
class ViewController: UIViewController {
var num = 0
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
print("dismissing")
super.dismiss(animated: flag, completion: completion)
}
deinit {
print("deinit view controller")
}
func logout1() {
dismiss(animated: false, completion: { print("logout1 ") })
}
// this doesn't work either
func logout2() {
navigationController?.dismiss(animated: false, completion: { print("logout2 ") })
}
}
var vc: ViewController? = ViewController()
var navController: UINavigationController? = UINavigationController(rootViewController: vc!)
let sideMenu = UIViewController()
sideMenu.present(navController!, animated: false, completion: nil)
vc?.logout2()
print(vc) // not nil
print(navController) // not nil