未正确显示视图控制器

View Controllers not being presented correctly

函数执行完毕后,我想返回我的 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)
    }

}

在呈现 ViewController 时,它不会显示导航栏,因为呈现取决于 UIViewController 而不是 NavigationViewcontroller。

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

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

} //使用弹出