0

I am new to iOS, I am trying to assign some values in customTab Controller I created. After I present the tabController , the values are not being the original values, what I sent. Please help me, where I am doing wrong.

let tabBarController = CustomTabBarController()
tabBarController.hideStatus = self.hideStatus
tabBarController.fromLanguageChange = self.fromLanguageChanged
tabBarController.testInt = 1234;
FF_DataPersistenceUtils.setIsFromNotification(isFromNotification: !self.isFromNotification)
let navController = UINavigationController(rootViewController: tabBarController)
self.present(navController, animated: false, completion: nil)

Custom tab controller .

class CustomTabBarController: UITabBarController {

    var hideStatus : Bool = false;
    var testInt : Int = 1;

    override func viewDidLoad() {
        super.viewDidLoad()

        print("hide status in custom tab : \(self.hideStatus)")  // false
        print("testInt values \(self.testInt)")  // 1
    }
}
Leo
  • 24,596
  • 11
  • 71
  • 92
Voora Tarun
  • 1,266
  • 1
  • 20
  • 38

1 Answers1

1

Try using instantiateViewControllerWithIdentifier function to instantiate the viewController

let storyboard = UIStoryboard(name: yourStoryBoardName, bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier :viewControllerName) as! CustomTabBarController
tabBarController.hideStatus = self.hideStatus
tabBarController.fromLanguageChange = self.fromLanguageChanged
tabBarController.testInt = 1234;
FF_DataPersistenceUtils.setIsFromNotification(isFromNotification: !self.isFromNotification)
let navController = UINavigationController(rootViewController: tabBarController)
self.present(navController, animated: false, completion: nil)
Aravind A R
  • 2,674
  • 1
  • 15
  • 25
  • Its worked . But I don't know why tabbarController is not maintaining variables, if create controller object in code. – Voora Tarun Jul 24 '17 at 06:49
  • instantiateViewControllerWithIdentifier will return a viewController with its subviews instantiated and will be similar to the one which was created in the storyboard. But in the other case you need to instantiate its subviews For more info refer this https://stackoverflow.com/questions/26131693/instantiate-view-controller-from-storyboard-vs-creating-new-instance – Aravind A R Jul 24 '17 at 07:14