2 Replies
      Latest reply on Nov 8, 2019 8:50 AM by Claude31
      japio Level 1 Level 1 (0 points)

        I am trying to fill an array in a different view controller and different class. What I am trying to do is check to see if a string is in an array in a different view controller. If the array does contain the string, then I want to display a message and if the array does not contain the string, then I want to append the string to the array. I actually want to send more data with the string. I am thinking that I need to use an array of tuples. I want a string for the name and a cost and monthly payment of the string. I want all of this information to be attached to the string. I am sending it to a table view in the other view controller. I only want to display the string in the table view. Then when the row of the string is clicked, I want it to take me to a different view controller and display the rest of the information attached to the clicked string in a table view. How would I do that? I also need to save the information so when I go to different table views, the information is still there. Can anyone provide me with examples of what to do?

        • Re: How do I fill an array in a different view controller without opening the view controller?
          Claude31 Level 8 Level 8 (7,305 points)

          Please edit your text to make it more readable. And ask precise question of what you cannot achieve, not the full story of your app, there are too many questions here.

           

          I am trying to fill an array in a different view controller and different class.

          What I am trying to do is check to see if a string is in an array in a different view controller. If the array does contain the string, then I want to display a message and if the array does not contain the string, then I want to append the string to the array.

           

          I actually want to send more data with the string.

          I am thinking that I need to use an array of tuples.

          - I want a string for the name and a cost and monthly payment of the string.

          - I want all of this information to be attached to the string.

           

          I am sending it to a table view in the other view controller. I only want to display the string in the table view. Then when the row of the string is clicked, I want it to take me to a different view controller and display the rest of the information attached to the clicked string in a table view.

           

          How would I do that? I also need to save the information so when I go to different table views, the information is still there. Can anyone provide me with examples of what to do?

           

          So, I will answer the first question

          I am trying to fill an array in a different view controller and different class.

          What I am trying to do is check to see if a string is in an array in a different view controller. If the array does contain the string, then I want to display a message and if the array does not contain the string, then I want to append the string to the array.

           

          There is a first controller VC1 and you want to use data from a second controller VC2.

          You link the class2 to VC2, but that is not necessary: class2 could be defined out of VC2.

           

          VC2 must be loaded, even though it may not be visible, but it must exist.

          The best here is to use delegation.

           

          See this thread where I explained the pattern (it is a very long thread, look at the beginning only). https://forums.developer.apple.com/thread/111569

           

          Tell if you don't understand something.