【问题标题】:View Controllers not being presented correctly视图控制器未正确呈现
【发布时间】:2018-07-10 00:09:01
【问题描述】:

当函数执行完毕后,我想回到我的 ProfileTabViewController。我想被发送回视图控制器,保持 ProfileTabViewControllers 与以前相同的导航栏和 UITabBarController。我现在拥有它的方式将它发送到 ProfileTavViewController 但我丢失了导航栏和标签栏。如何将其发送回原始 ProfileTabViewController。第一个图像是原始的 ViewController,第二个图像是它被发送回来的时候。

@IBAction func updateAction(_ sender: Any) {
     let newInterests = options.joined(separator: " , ")

    if newInterests == ""{
        showAlert(message: "Please select at least one interest.")
    }else{
       updateFunction()
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "ProfileTabViewController") as! UIViewController
        self.navigationController?.present(vc, animated: true, completion: nil)
    }

}

【问题讨论】:

  • 返回时如何关闭视图控制器?

标签: ios swift uinavigationcontroller uistoryboard


【解决方案1】:

在展示 ViewController 时,它不会显示导航栏,因为展示依赖于 UIViewController 而不是 NavigationViewcontroller。

你必须使用popViewController方法来获取导航栏。

for controller in self.navigationController?.viewControllers {
  if controller is ProfileViewController {
    self.navigationController!.popToViewController(controller, animated: true)
    break
}

} //使用弹出

【讨论】:

  • “UINavigationController”类型的值没有成员“push”
  • 原来显示的 tabBar 仍然不显示,我不希望能够滑回上一个屏幕。有什么方法可以让我在不做任何更改的情况下直接返回到原始 ProfileTabViewController。
  • 查看编辑后的答案
  • 正是我想要的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 2015-09-07
相关资源
最近更新 更多