ios - 如何在单击按钮时关闭选项卡栏 Controller 并返回到上一个 View Controller

标签 ios swift uiviewcontroller uitabbarcontroller

我正在构建这样的流程

FirstViewController -> SecondViewController -> Tab Bar View Controller(由1.ThirdViewController和2.FourthVIewController组成)

我正在打开标签栏 View Controller 作为 SecondViewController 的弹出窗口。但是,当我在 ThirdViewController 中单击一个按钮运行 (self.dismiss(animated: true, completion: nil)) 时,它会返回到 FirstViewController。 我想回到 SecondViewController

添加代码。 这就是我从 SecondViewController 打开标签栏 View Controller 的方式

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)

这就是我尝试从 Third View Controller 关闭标签栏 View Controller 的方式

  self.dismiss(animated: true, completion: nil))

最佳答案

您在 secondViewController 中添加了 tabBarController 作为 subview 。因此,您需要从 super View 中删除该 tabBarController View 。

为此,您需要一个 tabBarController 对象。

self.tabBarController?.view.removeFromSuperview()

关于ios - 如何在单击按钮时关闭选项卡栏 Controller 并返回到上一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43813965/

相关文章:

从选项卡 View Controller 切换到滑动手势时的 iOS Xcode 问题

jquery - 如何使用 javascript 显示 iOS Safari 地址栏?

ios - 比较数组中的对象并将相等的值放入单独的新对象中

iOS v10 或更低版本 : How to add UISearchController in the bottom of navigation bar Programmatically

iphone - 如何将模态视图添加到当前 View Controller 上?

ios - 使用自定义对象保存 NSMutableArray 时出现问题

ios - : works in this example? 手势如何

ios - 即使 iPhone 未处于事件状态,如何将 UserDefaults 数据获取到 Apple Watch

ios - 从另一个 UIViewController 调用方法没有可见效果

ios - isKindOfClass Bool if 语句记录 NO