自定义UIWindow及其根UINavigationController未被删除

时间:2017-02-04 12:08:58

标签: ios swift memory-management uiwindow

这是我创建和发布自定义UIWindow的方式:

class mainViewController: UIViewController {

    var customWindow: UIWindow?

    override func viewDidLoad() {
        super.viewDidLoad()

        self.customWindow = UIWindow()
        self.customWindow!.rootViewController = UINavigationController(rootViewController: UITableViewController(style: .plain))
        self.customWindow!.isHidden = false
    }

    deinit {
        self.customWindow?.rootViewController = nil
        self.customWindow?.isHidden = true
        self.customWindow = nil
    }
}

deinit之后,customWindow仍然存在于调试视图层次结构中,我缺少什么?

1 个答案:

答案 0 :(得分:-1)

以下是工作代码,完全摆脱了UIWindow及其兄弟层次结构:

if let rootVC = self.customWindow?.rootViewController {
    rootVC.dismiss(animated: false, completion: nil)
    self.customWindow = nil
}