导航控制器无法在多个情节提要中使用

时间:2018-09-11 09:45:00

标签: ios iphone swift uinavigationcontroller navigation

我有一个登录页面,它是我应用程序的开头。授予用户权限后,我会将其重定向到另一个情节提要。

在下面的照片1中:用户是否批准了白屏检查。如果是,我将重定向到Photo2。否则,我会将其重定向到登录页面(photo1中的红色页面)。

enter image description here

在Photo2下方:(我将显示一个包含一些数据的表格视图。当用户单击其中一个数据时,它将转到下一页(右一个)。

enter image description here

Photo3只是为了阐明Photo2。

enter image description here

问题是用户在表视图中单击一行后出现了Photo2。后退按钮不起作用(在应用程序中可见)

以下代码显示Photo1中白屏的代码:

 if let token = UserDefaults.standard.string(forKey: ConstantsKey.token){
            if !token.isEmpty{
                let storyboard : UIStoryboard = UIStoryboard(name: "MainTabBar", bundle: nil)
                let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
                let rootController = UINavigationController(rootViewController: vc)
                rootController.navigationBar.barTintColor = UIColor.init(red: 229/255, green: 28/255, blue: 60/255, alpha: 1)
                self.present(rootController, animated: true, completion: nil)
            }else{
//              let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

                let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                let vc = storyboard.instantiateViewController(withIdentifier: "LoginVc")

                self.present(vc, animated: true, completion: nil)
            }
        }else{
            let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "LoginVc")
            self.present(vc, animated: true, completion: nil)


        }

下面的代码显示授予用户权限后的登录页面:

let storyboard : UIStoryboard = UIStoryboard(name: "MainTabBar", bundle: nil)
                        let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
                        let rootController = UINavigationController(rootViewController: vc)
                        self.present(rootController, animated: true, completion: nil)

以下代码显示了将用户重定向到照片2中存在问题的页面的方式:

let next = self.storyboard?.instantiateViewController(withIdentifier:  "ShopVc") as! ShopViewController
    self.navigationController?.pushViewController(next, animated: true)

我还已将以下代码添加到Delegate中:

UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
    UINavigationBar.appearance().shadowImage = UIImage()

我在这里做错了什么可能导致此问题吗?

///////////////////////////////////////////////// ///////////////// ANSEWER 我创建了一个新项目,在这里工作正常!我认为这是xCode的问题!

1 个答案:

答案 0 :(得分:1)

重新启动您的项目,这可能是Xcode问题