Voora Tarun
Voora Tarun

Reputation: 1226

How to send data to custom tabbar controller in ios Swift

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
    }
}

Upvotes: 0

Views: 168

Answers (1)

Aravind A R
Aravind A R

Reputation: 2714

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)

Upvotes: 1

Related Questions