How to pass data between multiple (in my setup 3) ViewControllers?










0















enter image description hereenter image description here



I want to make an Flashcards App and the behaviour is that on the CoursesVC, the user can add courses and click on them. Then he gets the list with flashcards. There he can add more flashcards. The storage is managed by CoreData. When its clicked on the cell, I pass the data to the flashcards list with prepareForSegue. To add the flashcard, I had the same idea in mind, but it was not possible because the variable from the second view controller wasn't initialised, when prepareForSegue was created. Question: How can I pass a NSManagedObject from the first ViewController to the third ViewController in an appropriate way? (ugly way would be to let the view render before creating prepareForSegue)



The difference to questions like "how to pass data between ViewControllers" is that I have three ViewControllers. It won't work with using prepareForSegue at the first and at the second view controller, because when the prepareForSegue is created, the variable in the second VC is not defined yet, because the view is not initialised yet! Keep in mind that the segue from the second to the third view controller is "Present Modally" as "Page Sheet"!










share|improve this question



















  • 1





    Possible duplicate of Passing Data between View Controllers

    – Ratul Sharker
    Nov 15 '18 at 7:24






  • 1





    @lucas Use NotificationCenter to passing data..

    – Harshad Patel
    Nov 15 '18 at 8:07











  • @RatulSharker I don't want to pass between two VC but rather three ones. The problem is that the view with the var is not initialised yet when prepareForSegue of the second VC is created...

    – Lucas
    Nov 16 '18 at 17:21











  • @HarshadPatel but its a one-to-one-to-one relationship and not one-to-many relationship

    – Lucas
    Nov 16 '18 at 17:23















0















enter image description hereenter image description here



I want to make an Flashcards App and the behaviour is that on the CoursesVC, the user can add courses and click on them. Then he gets the list with flashcards. There he can add more flashcards. The storage is managed by CoreData. When its clicked on the cell, I pass the data to the flashcards list with prepareForSegue. To add the flashcard, I had the same idea in mind, but it was not possible because the variable from the second view controller wasn't initialised, when prepareForSegue was created. Question: How can I pass a NSManagedObject from the first ViewController to the third ViewController in an appropriate way? (ugly way would be to let the view render before creating prepareForSegue)



The difference to questions like "how to pass data between ViewControllers" is that I have three ViewControllers. It won't work with using prepareForSegue at the first and at the second view controller, because when the prepareForSegue is created, the variable in the second VC is not defined yet, because the view is not initialised yet! Keep in mind that the segue from the second to the third view controller is "Present Modally" as "Page Sheet"!










share|improve this question



















  • 1





    Possible duplicate of Passing Data between View Controllers

    – Ratul Sharker
    Nov 15 '18 at 7:24






  • 1





    @lucas Use NotificationCenter to passing data..

    – Harshad Patel
    Nov 15 '18 at 8:07











  • @RatulSharker I don't want to pass between two VC but rather three ones. The problem is that the view with the var is not initialised yet when prepareForSegue of the second VC is created...

    – Lucas
    Nov 16 '18 at 17:21











  • @HarshadPatel but its a one-to-one-to-one relationship and not one-to-many relationship

    – Lucas
    Nov 16 '18 at 17:23













0












0








0








enter image description hereenter image description here



I want to make an Flashcards App and the behaviour is that on the CoursesVC, the user can add courses and click on them. Then he gets the list with flashcards. There he can add more flashcards. The storage is managed by CoreData. When its clicked on the cell, I pass the data to the flashcards list with prepareForSegue. To add the flashcard, I had the same idea in mind, but it was not possible because the variable from the second view controller wasn't initialised, when prepareForSegue was created. Question: How can I pass a NSManagedObject from the first ViewController to the third ViewController in an appropriate way? (ugly way would be to let the view render before creating prepareForSegue)



The difference to questions like "how to pass data between ViewControllers" is that I have three ViewControllers. It won't work with using prepareForSegue at the first and at the second view controller, because when the prepareForSegue is created, the variable in the second VC is not defined yet, because the view is not initialised yet! Keep in mind that the segue from the second to the third view controller is "Present Modally" as "Page Sheet"!










share|improve this question
















enter image description hereenter image description here



I want to make an Flashcards App and the behaviour is that on the CoursesVC, the user can add courses and click on them. Then he gets the list with flashcards. There he can add more flashcards. The storage is managed by CoreData. When its clicked on the cell, I pass the data to the flashcards list with prepareForSegue. To add the flashcard, I had the same idea in mind, but it was not possible because the variable from the second view controller wasn't initialised, when prepareForSegue was created. Question: How can I pass a NSManagedObject from the first ViewController to the third ViewController in an appropriate way? (ugly way would be to let the view render before creating prepareForSegue)



The difference to questions like "how to pass data between ViewControllers" is that I have three ViewControllers. It won't work with using prepareForSegue at the first and at the second view controller, because when the prepareForSegue is created, the variable in the second VC is not defined yet, because the view is not initialised yet! Keep in mind that the segue from the second to the third view controller is "Present Modally" as "Page Sheet"!







ios swift core-data uiviewcontroller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 20:38







Lucas

















asked Nov 15 '18 at 7:11









LucasLucas

3019




3019







  • 1





    Possible duplicate of Passing Data between View Controllers

    – Ratul Sharker
    Nov 15 '18 at 7:24






  • 1





    @lucas Use NotificationCenter to passing data..

    – Harshad Patel
    Nov 15 '18 at 8:07











  • @RatulSharker I don't want to pass between two VC but rather three ones. The problem is that the view with the var is not initialised yet when prepareForSegue of the second VC is created...

    – Lucas
    Nov 16 '18 at 17:21











  • @HarshadPatel but its a one-to-one-to-one relationship and not one-to-many relationship

    – Lucas
    Nov 16 '18 at 17:23












  • 1





    Possible duplicate of Passing Data between View Controllers

    – Ratul Sharker
    Nov 15 '18 at 7:24






  • 1





    @lucas Use NotificationCenter to passing data..

    – Harshad Patel
    Nov 15 '18 at 8:07











  • @RatulSharker I don't want to pass between two VC but rather three ones. The problem is that the view with the var is not initialised yet when prepareForSegue of the second VC is created...

    – Lucas
    Nov 16 '18 at 17:21











  • @HarshadPatel but its a one-to-one-to-one relationship and not one-to-many relationship

    – Lucas
    Nov 16 '18 at 17:23







1




1





Possible duplicate of Passing Data between View Controllers

– Ratul Sharker
Nov 15 '18 at 7:24





Possible duplicate of Passing Data between View Controllers

– Ratul Sharker
Nov 15 '18 at 7:24




1




1





@lucas Use NotificationCenter to passing data..

– Harshad Patel
Nov 15 '18 at 8:07





@lucas Use NotificationCenter to passing data..

– Harshad Patel
Nov 15 '18 at 8:07













@RatulSharker I don't want to pass between two VC but rather three ones. The problem is that the view with the var is not initialised yet when prepareForSegue of the second VC is created...

– Lucas
Nov 16 '18 at 17:21





@RatulSharker I don't want to pass between two VC but rather three ones. The problem is that the view with the var is not initialised yet when prepareForSegue of the second VC is created...

– Lucas
Nov 16 '18 at 17:21













@HarshadPatel but its a one-to-one-to-one relationship and not one-to-many relationship

– Lucas
Nov 16 '18 at 17:23





@HarshadPatel but its a one-to-one-to-one relationship and not one-to-many relationship

– Lucas
Nov 16 '18 at 17:23












1 Answer
1






active

oldest

votes


















0














This is the solution basically: Swift : prepareForSegue with navigation controller



The problem was that the third view controller is embedded as a navigation controller. That is the reason why the prepareForSegue is different.



Solution is to use following prepareForSegue in the second VC:



override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
if let navigationVC = segue.destination as? UINavigationController, let myViewController = navigationVC.topViewController as? DViewController
myViewController.currentCourse = self.currentCourse







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%2f53314139%2fhow-to-pass-data-between-multiple-in-my-setup-3-viewcontrollers%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This is the solution basically: Swift : prepareForSegue with navigation controller



    The problem was that the third view controller is embedded as a navigation controller. That is the reason why the prepareForSegue is different.



    Solution is to use following prepareForSegue in the second VC:



    override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
    if let navigationVC = segue.destination as? UINavigationController, let myViewController = navigationVC.topViewController as? DViewController
    myViewController.currentCourse = self.currentCourse







    share|improve this answer



























      0














      This is the solution basically: Swift : prepareForSegue with navigation controller



      The problem was that the third view controller is embedded as a navigation controller. That is the reason why the prepareForSegue is different.



      Solution is to use following prepareForSegue in the second VC:



      override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
      if let navigationVC = segue.destination as? UINavigationController, let myViewController = navigationVC.topViewController as? DViewController
      myViewController.currentCourse = self.currentCourse







      share|improve this answer

























        0












        0








        0







        This is the solution basically: Swift : prepareForSegue with navigation controller



        The problem was that the third view controller is embedded as a navigation controller. That is the reason why the prepareForSegue is different.



        Solution is to use following prepareForSegue in the second VC:



        override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
        if let navigationVC = segue.destination as? UINavigationController, let myViewController = navigationVC.topViewController as? DViewController
        myViewController.currentCourse = self.currentCourse







        share|improve this answer













        This is the solution basically: Swift : prepareForSegue with navigation controller



        The problem was that the third view controller is embedded as a navigation controller. That is the reason why the prepareForSegue is different.



        Solution is to use following prepareForSegue in the second VC:



        override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
        if let navigationVC = segue.destination as? UINavigationController, let myViewController = navigationVC.topViewController as? DViewController
        myViewController.currentCourse = self.currentCourse








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 20:47









        LucasLucas

        3019




        3019





























            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%2f53314139%2fhow-to-pass-data-between-multiple-in-my-setup-3-viewcontrollers%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







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands