ios - 如果我创建一个新窗口并 makeKeyAndVisible,前一个窗口会发生什么

标签 ios swift

我正在尝试注销并返回登录 View Controller 。

所以我创建一个窗口,设置 rootViewController,然后 makeKeyAndVisible。 (不在 AppDelegate 中)

class AppManager: NSObject {
var window: UIWindow?

func goToLoginPage() {
    window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let loginVC = storyboard.instantiateViewController(withIdentifier: 
    "LoginVC") as! LoginVC
    window?.rootViewController = loginVC
    window?.makeKeyAndVisible()
}

}

它有效,但我在想前一个窗口会发生什么。会自动关闭并释放吗?如果没有,我需要这样做吗?

还是直接使用“UIApplication.shared.delegate?.window!!”更好像下面这样而不是创建一个新窗口?

UIApplication.shared.delegate?.window!!.rootViewController = homeVC

最佳答案

您可以从AppDelegate获取现有窗口并更改rootViewControlller

if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let window = appDelegate.window {
    window.rootViewController = loginVC
}

关于ios - 如果我创建一个新窗口并 makeKeyAndVisible,前一个窗口会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55912484/

相关文章:

ios - 更改 UIPopoverView 背景 + 箭头颜色

iphone - 角标(Badge),更新商品编号?

objective-c - RestKit 对象建模动态数据

ios - UICollectionView 不要重用 Cell

swift - 如何对 Swift 代码执行进行基准测试?

swift - Xcode 6 : iOS Swift. 如何获取游戏帧率(fps)?

ios - .htaccess 中重写文件的 MIME 类型不起作用

objective-c - 适用于 iOS 聊天应用程序的 XMPP 推送通知

ios - Use of undeclared type 'CustomObject' in swift - ios 报错

上传图片时iOS应用程序WKWebView错误