我想访问一个名为SubscriptionsViewController的孩子(第三个标签)
这就是我正在做的,但它不起作用。
var subscriptionsViewController: SubscriptionsViewController? {
get {
let viewControllers = self.childViewControllers
for viewController in viewControllers {
if let vc = viewController as? SubscriptionsViewController {
return vc
}
}
return nil
}
}
答案 0 :(得分:0)
假设您有一个标签栏控制器实例,您可以按如下方式执行:
var subscriptionsViewController: SubscriptionsViewController? {
get {
let viewControllers = tabController.viewControllers //assuming you have a property tabBarController
for viewController in viewControllers {
if viewController is SubscriptionsViewController {
return vc
}
}
return nil
}
}
答案 1 :(得分:0)
您可以使用以下内容访问标签栏控制器的子项:
self.tabBarController.viewControllers[2]