How to segue to previous screen using Swift without losing data in swift 4












2















I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:



self.performSegue(withIdentifier: "sugueToRules", sender: self)


on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)



when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.



how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?



i'm using swift 4










share|improve this question

























  • Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.

    – Alladinian
    Nov 22 '18 at 11:22













  • @Alladinian great answer, put it as an answer and i'll accept it

    – Chief Madog
    Nov 22 '18 at 11:28











  • @ChiefMadog Done. Glad that helped you :)

    – Alladinian
    Nov 22 '18 at 11:30
















2















I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:



self.performSegue(withIdentifier: "sugueToRules", sender: self)


on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)



when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.



how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?



i'm using swift 4










share|improve this question

























  • Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.

    – Alladinian
    Nov 22 '18 at 11:22













  • @Alladinian great answer, put it as an answer and i'll accept it

    – Chief Madog
    Nov 22 '18 at 11:28











  • @ChiefMadog Done. Glad that helped you :)

    – Alladinian
    Nov 22 '18 at 11:30














2












2








2








I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:



self.performSegue(withIdentifier: "sugueToRules", sender: self)


on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)



when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.



how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?



i'm using swift 4










share|improve this question
















I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:



self.performSegue(withIdentifier: "sugueToRules", sender: self)


on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)



when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.



how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?



i'm using swift 4







swift segue






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 11:19







Chief Madog

















asked Nov 22 '18 at 11:13









Chief MadogChief Madog

5691926




5691926













  • Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.

    – Alladinian
    Nov 22 '18 at 11:22













  • @Alladinian great answer, put it as an answer and i'll accept it

    – Chief Madog
    Nov 22 '18 at 11:28











  • @ChiefMadog Done. Glad that helped you :)

    – Alladinian
    Nov 22 '18 at 11:30



















  • Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.

    – Alladinian
    Nov 22 '18 at 11:22













  • @Alladinian great answer, put it as an answer and i'll accept it

    – Chief Madog
    Nov 22 '18 at 11:28











  • @ChiefMadog Done. Glad that helped you :)

    – Alladinian
    Nov 22 '18 at 11:30

















Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.

– Alladinian
Nov 22 '18 at 11:22







Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.

– Alladinian
Nov 22 '18 at 11:22















@Alladinian great answer, put it as an answer and i'll accept it

– Chief Madog
Nov 22 '18 at 11:28





@Alladinian great answer, put it as an answer and i'll accept it

– Chief Madog
Nov 22 '18 at 11:28













@ChiefMadog Done. Glad that helped you :)

– Alladinian
Nov 22 '18 at 11:30





@ChiefMadog Done. Glad that helped you :)

– Alladinian
Nov 22 '18 at 11:30












3 Answers
3






active

oldest

votes


















1














Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.



The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.






share|improve this answer































    0














    Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.



    self.navigationController?.popViewController(animated: true)
    self.dismiss(animated: true, completion: nil)





    share|improve this answer































      0














      you need to use UINavigationController for navigating UIViewController like -



      enter image description here






      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%2f53429726%2fhow-to-segue-to-previous-screen-using-swift-without-losing-data-in-swift-4%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.



        The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.






        share|improve this answer




























          1














          Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.



          The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.






          share|improve this answer


























            1












            1








            1







            Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.



            The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.






            share|improve this answer













            Make sure that they are managed by a UINavigationController. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.



            The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 11:30









            AlladinianAlladinian

            28.2k47073




            28.2k47073

























                0














                Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.



                self.navigationController?.popViewController(animated: true)
                self.dismiss(animated: true, completion: nil)





                share|improve this answer




























                  0














                  Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.



                  self.navigationController?.popViewController(animated: true)
                  self.dismiss(animated: true, completion: nil)





                  share|improve this answer


























                    0












                    0








                    0







                    Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.



                    self.navigationController?.popViewController(animated: true)
                    self.dismiss(animated: true, completion: nil)





                    share|improve this answer













                    Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.



                    self.navigationController?.popViewController(animated: true)
                    self.dismiss(animated: true, completion: nil)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 22 '18 at 11:40









                    Vaisakh KPVaisakh KP

                    172217




                    172217























                        0














                        you need to use UINavigationController for navigating UIViewController like -



                        enter image description here






                        share|improve this answer




























                          0














                          you need to use UINavigationController for navigating UIViewController like -



                          enter image description here






                          share|improve this answer


























                            0












                            0








                            0







                            you need to use UINavigationController for navigating UIViewController like -



                            enter image description here






                            share|improve this answer













                            you need to use UINavigationController for navigating UIViewController like -



                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '18 at 11:52









                            Deepti RaghavDeepti Raghav

                            288217




                            288217






























                                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%2f53429726%2fhow-to-segue-to-previous-screen-using-swift-without-losing-data-in-swift-4%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

                                MongoDB - Not Authorized To Execute Command

                                in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                                How to fix TextFormField cause rebuild widget in Flutter