Swift self.tabbar控制器?。选择索引并在另一个视图控制器中执行功能
我在选项卡栏控制器中有4个视图控制器,每个控制器都嵌入了导航控制器。问题是,我已经研究并发现在选项卡栏中从Viewcontroller0导航到ViewController1的最佳方法是使用Swift self.tabbar控制器?。选择索引并在另一个视图控制器中执行功能,swift,Swift,我在选项卡栏控制器中有4个视图控制器,每个控制器都嵌入了导航控制器。问题是,我已经研究并发现在选项卡栏中从Viewcontroller0导航到ViewController1的最佳方法是使用self.tabBarController?。selectedIndex=1,并且它工作正常。但是,我希望在导航后立即执行该功能。以下是我的尝试,但没有成功。有人有这个想法吗?非常感谢 @IBAction func GOGOBut(_ sender: Any) { self.tabBarContr
self.tabBarController?。selectedIndex=1
,并且它工作正常。但是,我希望在导航后立即执行该功能。以下是我的尝试,但没有成功。有人有这个想法吗?非常感谢
@IBAction func GOGOBut(_ sender: Any) {
self.tabBarController?.selectedIndex = 1
if let VC = presentingViewController as? TutorViewController {
VC.observeBBCases()
}
//NotificationCenter.default.post(name: NSNotification.Name(rawValue: "loadBAFS"), object: nil)
}
ObserveBCases()是TutorViewController中的函数
和self.tabBarController?.selectedIndex=1是使用索引
1
首先获取UINavigationController
,其中包含TutorViewController
。并获取导航控制器的根视图控制器TutorViewController
。然后可以调用方法observeBBCases
@IBAction func GOGOBut(_ sender: Any) {
if let navigationController = self.tabBarController?.viewControllers?[1] as? UINavigationController,
let vc = navigationController.viewControllers.first as? TutorViewController {
vc.observeBBCases()
self.tabBarController?.selectedIndex = 1
}
}