【发布时间】:2018-09-09 21:27:22
【问题描述】:
我正在尝试从子控制器访问对象,但它总是返回 nil。请检查以下代码。
let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let vc: UITabBarController = mainStoryboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
vc.selectedIndex = 2
let vc1 = vc.viewControllers?[2] as? FormViewController //this line returns nil
vc1?.fillUserData(dataDic: convertJsonStringToDictionary(jsonString: decodedURL))
vc1?.formViewDelegate = self
self.present(vc, animated: true, completion: nil)
请多指教。
【问题讨论】:
-
它可能为零,因为第三个视图控制器不是
FormViewController。也许它是一个导航控制器。 -
我确定第三个视图控制器是 formviewcontroller 并且它嵌入在导航控制器中。
-
这就是我的全部观点。
vc.viewControllers?[2]不是FormViewController,而是UINavigationController。这就是为什么你会得到nil。
标签: swift uiviewcontroller uitabbarcontroller uitabbar