我是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
}
}
答案 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)