Ios 为什么我的导航控制器在故事板中嵌入导航控制器并使用push segue后仍然为零?

Ios 为什么我的导航控制器在故事板中嵌入导航控制器并使用push segue后仍然为零?,ios,swift,uinavigationcontroller,Ios,Swift,Uinavigationcontroller,我试着阅读了Stackoverflow上的几个线程,但我认为我已经实现了所有这些线程,但仍然不起作用。这是我的故事板 因此,我隐藏(取消选中)导航栏的可见性,如下图所示,因为我想实现我自己的“导航标题”,如上图(右侧)所示: 当按下后退按钮时,我使用以下代码: self.navigationController?.popViewController(animated: true) 但不幸的是,在我检查后,导航控制器是零,我无法回到以前的VC 为了设置导航,我在app委托中设置了如下代码。如

我试着阅读了Stackoverflow上的几个线程,但我认为我已经实现了所有这些线程,但仍然不起作用。这是我的故事板

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

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

self.navigationController?.popViewController(animated: true)
但不幸的是,在我检查后,导航控制器是零,我无法回到以前的VC

为了设置导航,我在app委托中设置了如下代码。如果用户已经登录,那么它将被导航到HomeVC(主选项卡栏),否则它将被定向到上面我的故事板那样的登录序列

@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?不是导航控制器


这里出了什么问题?

只有在
窗口中有
导航堆栈
的情况下才能推/弹出

将您的
gotouthvc
替换为以下内容-

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()

}

Push/Pop
仅当
窗口中存在
导航堆栈时才可能

将您的
gotouthvc
替换为以下内容-

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()

}

从调用的位置-
self.navigationController?.popViewController(动画:true)
?@AmirKhan来自具有后退按钮的VC(第一个图像上的右侧按钮),您是否将第一个控制器设置为rootViewController,以及第二个控制器的按下方式,显示一些代码?然后你
segue
推到下一个viewController?检查导航堆栈是否为空。我添加了一些代码,从appdelagate启动VC@MuhammadWaqasBhati我不知道如何将firstVC视为根VC,而不是从您调用的位置-
self.navigationController?.popViewController(动画:true)
?@AmirKhan,来自具有后退按钮的VC(第一幅图像上的右侧按钮)您是否将第一个控制器设置为rootViewController,然后如何推送第二个控制器,显示一些代码?然后您
segue
推送到下一个viewController?检查导航堆栈是否为空。我添加了一些代码,从appdelagate启动VC@我不知道如何将第一个VC视为根VC