问题描述
所以在我的最后一个问题中,我试图从 AppDelegate 实例化,但它不起作用,所以在做了更多的研究之后,我一直看到 SceneDelegate 并决定试一试。令我惊讶的是,它奏效了,但并不是我想要的。
不要介意空格,我在自动布局方面遇到了问题,我将来会解决这个问题。我希望在从 SceneDelegate.swift
实例化 VC 时显示准确的图像,其中包含按钮、导航栏、用户交互以及正确显示的所有内容。
现在,当我在 SceneDelegate
willConnectTo()
方法中运行这段代码时...
func scene(_ scene: UIScene,willConnectTo session: UISceneSession,options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard,the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
self.window = self.window ?? UIWindow()
let storyboard = UIStoryboard(name: "Main",bundle: nil)
let auth = Auth.auth()
auth.addStateDidChangeListener { (_,user) in
if let user = user {
let alreadyLoggedInViewController = storyboard.instantiateViewController(withIdentifier: Constants.StoryboardIDs.StudentEventDashboardStoryboardID) as! StudentSegmentedTableViewController
self.window!.rootViewController = alreadyLoggedInViewController
self.window!.makeKeyAndVisible()
}
}
guard let _ = (scene as? UIWindowScene) else { return }
}
我最终得到了这个......
我真的很高兴看到它,因为我的代码终于可以工作了,但它没有显示带有栏按钮项的导航栏,这有点压抑了快乐。分段控件仍然是交互式的,tableview 仍然会刷新,这很好,但我只想要我的普通 VC,这样用户就可以正常使用该应用程序并查看所有其他 UI。如果有人可以帮助解决这个问题,那对我来说将是一个很大的帮助。提前致谢。
解决方法
太棒了,我需要做的就是添加这行代码..
let navigationizedVC = UINavigationController(rootViewController: alreadyLoggedInViewController)
然后就这样做...
self.window!.rootViewController = navigationizedVC
完美运行。