How to get back from tabbar view controller?












0















My Initial screen is HomeViewController, from HomeViewController I am move to TabBarViewController. Now, I want to move back to HomeViewController. I am using following code for that:



self.navigationController?.popViewController(animated: true)


But it's not working.










share|improve this question

























  • Can you show how you are adding tabBarController from HomeViewController? Most probably you can do UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()

    – Kamran
    Nov 22 '18 at 6:58













  • I am using button for navigation from HomeViewController to Tabbar ViewController @Kamran

    – MeMouli
    Nov 22 '18 at 7:02






  • 1





    How are you moving from HomeViewController to Tab Controller? Are you using navigation controller to push your Tabbar ViewController?

    – Natarajan
    Nov 22 '18 at 7:08











  • Have you initialize your HomeViewController with NavigationController?

    – hpp
    Nov 22 '18 at 7:29











  • yes i initialize HomeViewController with NavigationController

    – MeMouli
    Nov 22 '18 at 9:46


















0















My Initial screen is HomeViewController, from HomeViewController I am move to TabBarViewController. Now, I want to move back to HomeViewController. I am using following code for that:



self.navigationController?.popViewController(animated: true)


But it's not working.










share|improve this question

























  • Can you show how you are adding tabBarController from HomeViewController? Most probably you can do UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()

    – Kamran
    Nov 22 '18 at 6:58













  • I am using button for navigation from HomeViewController to Tabbar ViewController @Kamran

    – MeMouli
    Nov 22 '18 at 7:02






  • 1





    How are you moving from HomeViewController to Tab Controller? Are you using navigation controller to push your Tabbar ViewController?

    – Natarajan
    Nov 22 '18 at 7:08











  • Have you initialize your HomeViewController with NavigationController?

    – hpp
    Nov 22 '18 at 7:29











  • yes i initialize HomeViewController with NavigationController

    – MeMouli
    Nov 22 '18 at 9:46
















0












0








0








My Initial screen is HomeViewController, from HomeViewController I am move to TabBarViewController. Now, I want to move back to HomeViewController. I am using following code for that:



self.navigationController?.popViewController(animated: true)


But it's not working.










share|improve this question
















My Initial screen is HomeViewController, from HomeViewController I am move to TabBarViewController. Now, I want to move back to HomeViewController. I am using following code for that:



self.navigationController?.popViewController(animated: true)


But it's not working.







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 8:03









John Kennedy

2,61321026




2,61321026










asked Nov 22 '18 at 6:56









MeMouliMeMouli

96




96













  • Can you show how you are adding tabBarController from HomeViewController? Most probably you can do UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()

    – Kamran
    Nov 22 '18 at 6:58













  • I am using button for navigation from HomeViewController to Tabbar ViewController @Kamran

    – MeMouli
    Nov 22 '18 at 7:02






  • 1





    How are you moving from HomeViewController to Tab Controller? Are you using navigation controller to push your Tabbar ViewController?

    – Natarajan
    Nov 22 '18 at 7:08











  • Have you initialize your HomeViewController with NavigationController?

    – hpp
    Nov 22 '18 at 7:29











  • yes i initialize HomeViewController with NavigationController

    – MeMouli
    Nov 22 '18 at 9:46





















  • Can you show how you are adding tabBarController from HomeViewController? Most probably you can do UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()

    – Kamran
    Nov 22 '18 at 6:58













  • I am using button for navigation from HomeViewController to Tabbar ViewController @Kamran

    – MeMouli
    Nov 22 '18 at 7:02






  • 1





    How are you moving from HomeViewController to Tab Controller? Are you using navigation controller to push your Tabbar ViewController?

    – Natarajan
    Nov 22 '18 at 7:08











  • Have you initialize your HomeViewController with NavigationController?

    – hpp
    Nov 22 '18 at 7:29











  • yes i initialize HomeViewController with NavigationController

    – MeMouli
    Nov 22 '18 at 9:46



















Can you show how you are adding tabBarController from HomeViewController? Most probably you can do UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()

– Kamran
Nov 22 '18 at 6:58







Can you show how you are adding tabBarController from HomeViewController? Most probably you can do UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()

– Kamran
Nov 22 '18 at 6:58















I am using button for navigation from HomeViewController to Tabbar ViewController @Kamran

– MeMouli
Nov 22 '18 at 7:02





I am using button for navigation from HomeViewController to Tabbar ViewController @Kamran

– MeMouli
Nov 22 '18 at 7:02




1




1





How are you moving from HomeViewController to Tab Controller? Are you using navigation controller to push your Tabbar ViewController?

– Natarajan
Nov 22 '18 at 7:08





How are you moving from HomeViewController to Tab Controller? Are you using navigation controller to push your Tabbar ViewController?

– Natarajan
Nov 22 '18 at 7:08













Have you initialize your HomeViewController with NavigationController?

– hpp
Nov 22 '18 at 7:29





Have you initialize your HomeViewController with NavigationController?

– hpp
Nov 22 '18 at 7:29













yes i initialize HomeViewController with NavigationController

– MeMouli
Nov 22 '18 at 9:46







yes i initialize HomeViewController with NavigationController

– MeMouli
Nov 22 '18 at 9:46














4 Answers
4






active

oldest

votes


















0














Yah, It's not working, as well as navigationController?.popToRootViewController(animated: true) not working so you can push to HomeViewController from TabBarViewController.



self.navigationController?.pushViewController(vc, animated: false)





share|improve this answer
























  • It works, but navigation items are missing after i comeback from another view controller

    – MeMouli
    Nov 22 '18 at 7:54



















0














How to get back from tabbar controller depends on how you got to it in the first plase.



If you pushed it into navigation stack, you need to call popViewController(animated:). This is clearly not your case.



You could've presented it modally. Then you need to dismiss(animated:, completion:).



If you set the tabbar controller as the window's root, then you need to reset the root with your HomeViewController. E.g.



UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()





share|improve this answer































    0














    You should custom a UITabBarViewController



    When you want go to TabBarVC from Home, you push a navigation has root is a TabBarViewController.
    At TabBarViewController, if you want to back to Home, call popToViewController method of nagicationVC.



    Ex:



    class HomeVC: UIViewController {



    @IBAction func goToTabBarVC(_ sender: Any) {
    let tabBar = TabBarVC()
    let navigation = UINavigationController(rootViewController: tabBar)
    navigationController?.pushViewController(navigation, animated: true)
    }


    }



    class TabBarVC: UITabBarController {



    @IBAction func backToHome(_ sender: Any) {
    navigationController?.popViewController(animated: true)
    }


    }






    share|improve this answer
























    • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

      – MeMouli
      Nov 22 '18 at 7:46











    • I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

      – Leo LE
      Nov 23 '18 at 6:41





















    0














    In the app delegate file put following code in applicationDidFinishLaunching method.



    let st = UIStoryboard(name: "Main", bundle: nil)
    let homeVC = [st initializeViewControllerWithIdentifier:"HomeVC"]

    let navigation = UINavigationController(rootViewController: homeVC)
    self.window??.rootViewController = navigation


    or



    You can directly embed the Navigation controller to the home view controller from storyboard.



    Thanks






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425391%2fhow-to-get-back-from-tabbar-view-controller%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Yah, It's not working, as well as navigationController?.popToRootViewController(animated: true) not working so you can push to HomeViewController from TabBarViewController.



      self.navigationController?.pushViewController(vc, animated: false)





      share|improve this answer
























      • It works, but navigation items are missing after i comeback from another view controller

        – MeMouli
        Nov 22 '18 at 7:54
















      0














      Yah, It's not working, as well as navigationController?.popToRootViewController(animated: true) not working so you can push to HomeViewController from TabBarViewController.



      self.navigationController?.pushViewController(vc, animated: false)





      share|improve this answer
























      • It works, but navigation items are missing after i comeback from another view controller

        – MeMouli
        Nov 22 '18 at 7:54














      0












      0








      0







      Yah, It's not working, as well as navigationController?.popToRootViewController(animated: true) not working so you can push to HomeViewController from TabBarViewController.



      self.navigationController?.pushViewController(vc, animated: false)





      share|improve this answer













      Yah, It's not working, as well as navigationController?.popToRootViewController(animated: true) not working so you can push to HomeViewController from TabBarViewController.



      self.navigationController?.pushViewController(vc, animated: false)






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 22 '18 at 7:09









      Haresh GediyaHaresh Gediya

      265




      265













      • It works, but navigation items are missing after i comeback from another view controller

        – MeMouli
        Nov 22 '18 at 7:54



















      • It works, but navigation items are missing after i comeback from another view controller

        – MeMouli
        Nov 22 '18 at 7:54

















      It works, but navigation items are missing after i comeback from another view controller

      – MeMouli
      Nov 22 '18 at 7:54





      It works, but navigation items are missing after i comeback from another view controller

      – MeMouli
      Nov 22 '18 at 7:54













      0














      How to get back from tabbar controller depends on how you got to it in the first plase.



      If you pushed it into navigation stack, you need to call popViewController(animated:). This is clearly not your case.



      You could've presented it modally. Then you need to dismiss(animated:, completion:).



      If you set the tabbar controller as the window's root, then you need to reset the root with your HomeViewController. E.g.



      UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()





      share|improve this answer




























        0














        How to get back from tabbar controller depends on how you got to it in the first plase.



        If you pushed it into navigation stack, you need to call popViewController(animated:). This is clearly not your case.



        You could've presented it modally. Then you need to dismiss(animated:, completion:).



        If you set the tabbar controller as the window's root, then you need to reset the root with your HomeViewController. E.g.



        UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()





        share|improve this answer


























          0












          0








          0







          How to get back from tabbar controller depends on how you got to it in the first plase.



          If you pushed it into navigation stack, you need to call popViewController(animated:). This is clearly not your case.



          You could've presented it modally. Then you need to dismiss(animated:, completion:).



          If you set the tabbar controller as the window's root, then you need to reset the root with your HomeViewController. E.g.



          UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()





          share|improve this answer













          How to get back from tabbar controller depends on how you got to it in the first plase.



          If you pushed it into navigation stack, you need to call popViewController(animated:). This is clearly not your case.



          You could've presented it modally. Then you need to dismiss(animated:, completion:).



          If you set the tabbar controller as the window's root, then you need to reset the root with your HomeViewController. E.g.



          UIApplication.shared.delegate?.window??.rootViewController = HomeViewController()






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 7:15









          EvgeniyEvgeniy

          475413




          475413























              0














              You should custom a UITabBarViewController



              When you want go to TabBarVC from Home, you push a navigation has root is a TabBarViewController.
              At TabBarViewController, if you want to back to Home, call popToViewController method of nagicationVC.



              Ex:



              class HomeVC: UIViewController {



              @IBAction func goToTabBarVC(_ sender: Any) {
              let tabBar = TabBarVC()
              let navigation = UINavigationController(rootViewController: tabBar)
              navigationController?.pushViewController(navigation, animated: true)
              }


              }



              class TabBarVC: UITabBarController {



              @IBAction func backToHome(_ sender: Any) {
              navigationController?.popViewController(animated: true)
              }


              }






              share|improve this answer
























              • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

                – MeMouli
                Nov 22 '18 at 7:46











              • I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

                – Leo LE
                Nov 23 '18 at 6:41


















              0














              You should custom a UITabBarViewController



              When you want go to TabBarVC from Home, you push a navigation has root is a TabBarViewController.
              At TabBarViewController, if you want to back to Home, call popToViewController method of nagicationVC.



              Ex:



              class HomeVC: UIViewController {



              @IBAction func goToTabBarVC(_ sender: Any) {
              let tabBar = TabBarVC()
              let navigation = UINavigationController(rootViewController: tabBar)
              navigationController?.pushViewController(navigation, animated: true)
              }


              }



              class TabBarVC: UITabBarController {



              @IBAction func backToHome(_ sender: Any) {
              navigationController?.popViewController(animated: true)
              }


              }






              share|improve this answer
























              • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

                – MeMouli
                Nov 22 '18 at 7:46











              • I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

                – Leo LE
                Nov 23 '18 at 6:41
















              0












              0








              0







              You should custom a UITabBarViewController



              When you want go to TabBarVC from Home, you push a navigation has root is a TabBarViewController.
              At TabBarViewController, if you want to back to Home, call popToViewController method of nagicationVC.



              Ex:



              class HomeVC: UIViewController {



              @IBAction func goToTabBarVC(_ sender: Any) {
              let tabBar = TabBarVC()
              let navigation = UINavigationController(rootViewController: tabBar)
              navigationController?.pushViewController(navigation, animated: true)
              }


              }



              class TabBarVC: UITabBarController {



              @IBAction func backToHome(_ sender: Any) {
              navigationController?.popViewController(animated: true)
              }


              }






              share|improve this answer













              You should custom a UITabBarViewController



              When you want go to TabBarVC from Home, you push a navigation has root is a TabBarViewController.
              At TabBarViewController, if you want to back to Home, call popToViewController method of nagicationVC.



              Ex:



              class HomeVC: UIViewController {



              @IBAction func goToTabBarVC(_ sender: Any) {
              let tabBar = TabBarVC()
              let navigation = UINavigationController(rootViewController: tabBar)
              navigationController?.pushViewController(navigation, animated: true)
              }


              }



              class TabBarVC: UITabBarController {



              @IBAction func backToHome(_ sender: Any) {
              navigationController?.popViewController(animated: true)
              }


              }







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 22 '18 at 7:19









              Leo LELeo LE

              215




              215













              • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

                – MeMouli
                Nov 22 '18 at 7:46











              • I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

                – Leo LE
                Nov 23 '18 at 6:41





















              • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

                – MeMouli
                Nov 22 '18 at 7:46











              • I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

                – Leo LE
                Nov 23 '18 at 6:41



















              Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

              – MeMouli
              Nov 22 '18 at 7:46





              Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

              – MeMouli
              Nov 22 '18 at 7:46













              I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

              – Leo LE
              Nov 23 '18 at 6:41







              I only given a idea, it not enough code to compile success. You must add some code, ex HomeViewController is child of a UINavigationController.

              – Leo LE
              Nov 23 '18 at 6:41













              0














              In the app delegate file put following code in applicationDidFinishLaunching method.



              let st = UIStoryboard(name: "Main", bundle: nil)
              let homeVC = [st initializeViewControllerWithIdentifier:"HomeVC"]

              let navigation = UINavigationController(rootViewController: homeVC)
              self.window??.rootViewController = navigation


              or



              You can directly embed the Navigation controller to the home view controller from storyboard.



              Thanks






              share|improve this answer






























                0














                In the app delegate file put following code in applicationDidFinishLaunching method.



                let st = UIStoryboard(name: "Main", bundle: nil)
                let homeVC = [st initializeViewControllerWithIdentifier:"HomeVC"]

                let navigation = UINavigationController(rootViewController: homeVC)
                self.window??.rootViewController = navigation


                or



                You can directly embed the Navigation controller to the home view controller from storyboard.



                Thanks






                share|improve this answer




























                  0












                  0








                  0







                  In the app delegate file put following code in applicationDidFinishLaunching method.



                  let st = UIStoryboard(name: "Main", bundle: nil)
                  let homeVC = [st initializeViewControllerWithIdentifier:"HomeVC"]

                  let navigation = UINavigationController(rootViewController: homeVC)
                  self.window??.rootViewController = navigation


                  or



                  You can directly embed the Navigation controller to the home view controller from storyboard.



                  Thanks






                  share|improve this answer















                  In the app delegate file put following code in applicationDidFinishLaunching method.



                  let st = UIStoryboard(name: "Main", bundle: nil)
                  let homeVC = [st initializeViewControllerWithIdentifier:"HomeVC"]

                  let navigation = UINavigationController(rootViewController: homeVC)
                  self.window??.rootViewController = navigation


                  or



                  You can directly embed the Navigation controller to the home view controller from storyboard.



                  Thanks







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 22 '18 at 8:02









                  John Kennedy

                  2,61321026




                  2,61321026










                  answered Nov 22 '18 at 7:33









                  hpphpp

                  584212




                  584212






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425391%2fhow-to-get-back-from-tabbar-view-controller%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin