gpt4 book ai didi

ios - 为什么即使在 Storyboard中嵌入导航 Controller 并使用 push segue 后,我的导航 Controller 仍为零?

转载 作者:行者123 更新时间:2023-11-28 11:35:49 26 4
gpt4 key购买 nike

我已尝试阅读 Stackoverflow 上的几个主题,但我认为我已经实现了所有主题,但仍然无法正常工作。这是我的 Storyboard

enter image description here

所以我隐藏(取消选中)导航栏可见性,如下图所示,因为我想实现我自己的“导航标题”,如上图(右图)所示: enter image description here

当按下后退按钮时,我使用下面的代码:

self.navigationController?.popViewController(animated: true)

但不幸的是,在我检查之后,导航 Controller 为零,我无法返回到之前的 VC。

我像这样在应用程序委托(delegate)中设置了一些代码,以设置导航。如果用户已经登录,那么它将被导航到 HomeVC(主标签栏),否则它将被定向到登录序列,就像我上面的 Storyboard一样

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// to print Local Database Location, uncomment the line below if you want to trace the location of Realm Database / User Default
// print("Location of Realm Database: \(Realm.Configuration.defaultConfiguration.fileURL)")



checkHasLoggedInOrNot()




return true
}




}

extension AppDelegate {
// MARK: - Helper Methods

func checkHasLoggedInOrNot() {
let userHasLoggedIn = AuthService.shared.hasLoggedIn

if userHasLoggedIn {
goToMainTabBar()
} else {
goToAuthVC()
}
}


}

extension AppDelegate {
// MARK: - Navigation

func goToMainTabBar() {
let storyboard = UIStoryboard(name: StoryBoardName.Main.rawValue, bundle: nil)
let mainTabBar = storyboard.instantiateViewController(withIdentifier: MainStoryboardData.StoryBoardID.MainTabBar.rawValue)
window?.rootViewController = mainTabBar
}

func goToAuthVC() {
let storyboard = UIStoryboard(name: StoryBoardName.Auth.rawValue, bundle: nil)
let authVC = storyboard.instantiateViewController(withIdentifier: AuthStoryboardData.StoryBoardID.AuthVC.rawValue)
window?.rootViewController = authVC
}
}

也许问题出在下面的代码上?

func goToAuthVC() {
let storyboard = UIStoryboard(name: StoryBoardName.Auth.rawValue, bundle: nil)
let authVC = storyboard.instantiateViewController(withIdentifier: AuthStoryboardData.StoryBoardID.AuthVC.rawValue)
window?.rootViewController = authVC
}

因为它指向 AuthVC ?不是导航 Controller ?

这里出了什么问题?

最佳答案

Push/Pop 仅当 window 中有 Navigation stack 时才有可能。

将您的 goToAuthVC 替换为以下 -

func goToAuthVC() {

let storyboard = UIStoryboard(name: StoryBoardName.Auth.rawValue, bundle: nil)
let authVC = storyboard.instantiateViewController(withIdentifier: AuthStoryboardData.StoryBoardID.AuthVC.rawValue)
let navigationController = UINavigationController(rootViewController: authVC)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()

}

关于ios - 为什么即使在 Storyboard中嵌入导航 Controller 并使用 push segue 后,我的导航 Controller 仍为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55449518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com