如何将数据发送到ios Swift中的自定义tabbar控制器

时间:2017-07-24 06:20:57

标签: ios swift

我是iOS新手,我正在尝试在我创建的customTab控制器中分配一些值。在我呈现tabController之后,值不是我发送的原始值。请帮助我,我做错了。

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)

自定义标签控制器。

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

1 个答案:

答案 0 :(得分:1)

尝试使用instantiateViewControllerWithIdentifier函数来实例化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)