Segue Data Transfer Best Practice

Discussion in 'iOS Programming' started by DannyBres, Jun 17, 2015.

  1. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #1
    Today I have a VC (say called pickVC) that allows the user to pick from a list, i present it modally. I have implemented it like UIImagePickerController, it has a delegate protocol that has didPickItem... didCancelSelection... etc. This works well today.

    I create an instance of pickVC, set delegate as the presentingVC, present it, on didSelectRowAt... I fire the delegate method and dismiss it.

    I think this is a good way to do it.

    I know what to change the architecture to be a UISplitViewController, from reading around, I should use a segue from my MasterVC to my DetailVC. Using a show detail segue, a brand new instance of the detailVC is created with each segue. In prepareForSegue, what is the best way to transfer the data? have a public method on the detailVC and call it from the masterVC to set it up? Use my delegate protocol still?

    Thanks,

    Daniel Breslan
     
  2. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #2
    I'm going through the Code Coalition videos right now and just happen to be going through that subject right now. I'm not an expert on the process, he's using arrays and a dictionary for data storage and TBH, it's a bit of a convoluted process that I haven't become an expert on yet.

    I'm wondering if storing in a traditional database system like SQLite or CoreData would be more straight forward.

    One problem I noticed with the solution from Code Coalition was that if the data structure changes, you have to change the code.

    I was thinking that a different object to store the data should be available to store the data in all objects.

    Another option would be a singleton type approach for the data.

    What method are you using now?
     
  3. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Yes, have a public method on the detailVC and set a data model object that lets the detailVC know what to display. The delegate protocol is probably not relevant.
     

Share This Page