0

它是我的空项目,有两个 UIViewController,没有强引用:

应用委托:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        loadWindow()
        
        return true
    }
    
    
    func loadWindow() {
        window = UIWindow(frame: UIScreen.main.bounds)
        let startVC = UIStoryboard(name: "Start", bundle: nil).instantiateViewController(withIdentifier: String(describing: StartVC.self)) as! StartVC
        window?.rootViewController = startVC
        window?.makeKeyAndVisible()
    }
}


extension AppDelegate {
    
    static var shared: AppDelegate {
        return UIApplication.shared.delegate as! AppDelegate
    }
    
}

启动VC:

class StartVC: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        goToMain()
    }
    
    deinit {
        print("StartVC deinit")
    }
    
    func goToMain() {
        
        let mainNC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MainNC") as! UINavigationController
        mainNC.modalPresentationStyle = .fullScreen
        mainNC.modalTransitionStyle = .crossDissolve
        present(mainNC, animated: true)
        
    }
    
}

主VC:

class MainVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    deinit {
        print("MainVC deinit")
    }
    
    @IBAction func realoadWindow(_ sender: UIButton) {
        print("realoadWindow")
        AppDelegate.shared.loadWindow()
    }

}

主故事板

单击按钮后重新加载窗口(MainVC) deinit 未在iOS 15上调用,但在iOS 14.4上它OK

iOS 14.4 控制台:

iOS 14.4

iOS 15 控制台:

iOS 15

我在 MacOS Big Sur 上使用 Xcode 13 beta 5 和 iPhone 模拟器。

4

0 回答 0