[英]How to go from one view controller to another view controller through tab bar controller when Click a button in the first view controller
[英]How to dismiss a Tab Bar Controller and go back to previous view controller on click of button
我正在建立这样的流程
FirstViewController -> SecondViewController -> Tab Bar View Controller(由1.ThirdViewController和2.FourthVIewController组成)
我正在打开标签栏视图控制器作为 SecondViewController 的弹出窗口。 但是,当我单击 ThirdViewController 中的按钮运行 (self.dismiss(animated: true, completion: nil)) 时,它会返回到 FirstViewController。 我想回到 SecondViewController
添加代码。 这就是我从 SecondViewController 打开标签栏视图控制器的方式
let popupVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "tabBarVC") as! UITabBarController
self.addChildViewController(popupVC)
popupVC.view.frame = self.view.frame
self.view.addSubview(popupVC.view)
popupVC.didMove(toParentViewController: self)
这就是我尝试关闭第三个视图控制器的选项卡栏视图控制器的方式
self.dismiss(animated: true, completion: nil))
您在 secondViewController 中添加了 tabBarController 作为子视图。 所以你需要从超级视图中删除那个 tabBarController 视图。
为此,您需要一个 tabBarController 对象。
self.tabBarController?.view.removeFromSuperview()
您可以在流程中使用导航控制器,因此当您在 ThirdViewController 中时,请使用:
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "second") as? SecondViewController {
self.navigationController?.popToViewController(vc, animated: true)
}
下面的代码能够删除 tabview 并带我回到 SecondViewController
self.tabBarController?.view.removeFromSuperview()
切换到 UITabBar 上的其他项,其中 0 插入 UTTabBar 项的索引:
self.tabBarController?.selectedIndex = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.