简体   繁体   中英

View Controllers not being presented correctly

When the function is done executing I want to go back to my ProfileTabViewController. I want to get sent back to the view controller keeping the ProfileTabViewControllers same navigation bar and UITabBarController from before. The way I have it now it gets sent to the ProfileTavViewController but I lose my navigation bar as well as the tab bar. How do I just send it back to the original ProfileTabViewController. The first image is the original ViewController and the second image is when it gets sent back.

原始的ProfileTabViewController 当我退回

@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)
    }

}

While Presenting a ViewController it will not show navigationbar beacause presentation depends on UIViewController not NavigationViewcontroller.

You have to use popViewController method to get navigation bar.

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

} //Use Pop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM