简体   繁体   中英

Navigation controller is not working in multiple storyboard

I have a login page a the beginning of my app. when user is granted I'll redirect it to another storyboard.

In this below photo1: the white screen check is user granted or not. if yes I'll redirect the to Photo2. else I'll redirect them to the login page ( red pages in photo1).)

在此处输入图片说明

In below Photo2:(I'll show a table view which contains some data. when the user clicks one of them, it goes to the next page (right one).)

在此处输入图片说明

And Photo3 is just to clarify Photo2.

在此处输入图片说明

The problem is Photo2 after a user clicked a row in the table view. the back button does not work (it is visible in the app)

The code below shows the white screen's code in 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)


        }

The code below shows the login page after the user is granted:

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)

The code below shows the way I redirect the user to the page which has the problem in the photo 2:

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

I Also have added the code below to Delegate :

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

Am I doing something wrong here which might cause this problem?

//////////////////////////////////////////////////////////////// ANSEWER I created a new project which works fine there! I think it was the xCode's problem!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM