Search code examples
iosiphoneswiftuser-interfaceuinavigationcontroller

sending ui data in swift


I'm a bit beginner in SWIFT and right now I'm facing a problem whit UI. In this PHOTO I'm showing my UI to clarify what I'm saying . in part 1 I check if the user is logged in to his account or not, if yes it goes to part 3, if not it goes to part 2. when user login in part 2, I transfer the user to part 3. part 1 and 2 should not have any navigation color, though the part 3 should have the navigation color.

Part 1:

if let token = UserDefaults.standard.string(forKey: ConstantsKey.token){
        if !token.isEmpty{
            let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
            let rootController = UINavigationController(rootViewController: vc)
            self.present(rootController, animated: true, completion: nil)
        }else{
            let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "LoginVc")
            let rootController = UINavigationController(rootViewController: vc)
            self.present(rootController, animated: true, completion: nil)
        }
    }else{
        let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "LoginVc")
        let rootController = UINavigationController(rootViewController: vc)
        self.present(rootController, animated: true, completion: nil)
    }

Part 2:

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)

I want to have that red color in part 3 ! but whenever I run the application in shows the defualt color of the navigation controller

does anybody knows how should I manage/handle this problem?


Solution

  • Then in Part 1:

        if !token.isEmpty{
                    let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                    let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
                    let rootController = UINavigationController(rootViewController: vc)
                    rootController?.navigationBar.barTintColor = UIColor.red
                    self.present(rootController, animated: true, completion: nil)
    

    Part 2:

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