0

I have one tableViewController that makes an API call, gets data, and I store it in a variable sortedData, which is an array, that contains dictionaries. Once a user pushes the button, NO segue occurs, but I do:

self.tabBarController!.selectedIndex = 2;

Now I need to load the data from this sortedData variable in the new tableViewController2, and display it to the user however I see fit. I have searched far and wide, and cannot find a good way to accomplish this. babysteps would be ideal for me because I am very confused how to do this.

This array will be changing everytime the user does a search, so I don't think I can use it as a singleton

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Waffles
  • 123
  • 2
  • 10
  • Please actually read the entirety of all the answers in the duplicate question. In fact, part of one of the answers (the highest upvoted one) specifically addresses this ***exact*** scenario. Also, don't edit meta commentary into your questions. – nhgrif Mar 30 '16 at 01:51
  • From the duplicate question's most upvoted answer: *We might also want to share information between tabs in a `UITabBarController`.* – nhgrif Mar 30 '16 at 01:54
  • Apologies, I wasn't sure how to communicate with you. I missed that. Thank you! – Waffles Mar 30 '16 at 02:02

1 Answers1

0

Is there any reason you're trying to avoid segues? They're tough to wrap your mind around at first but can be really useful if you're new to iOS dev. If you can figure out how to draw segues from the storyboard inspector, you can use a method called prepareForSegue, in which you specify what data you will be passing through the segue to the other viewController, then presentThatViewController.

You COULD look into NSNotificationCenter, in which you could post a notification to your app in the firstTableViewController after the data has been received and placed into your storedData array, then add what is called a listener to the secondTableViewController, most likely in the viewDidLoad method. Imagine you're in a house with four rooms, you're in one room and I'm in another. You want to paint a picture based on the data I'm giving you, but you can't do it until I "notify" you, or in this example shout out, "Hey, paint this!". This is a much more hacky way to get this done, and while NSNotificationCenter is a great tool in the developer's belt, its making things more complicated than using segues, in my opinion.

  • I am using segues throughout the majority of my project, jus tin this case it wouldn't make any sense. the user does a search, hits submit, and then another tab should be in focus, displaying the results. there should NOT be a back button or anything, as there are multiple ways to search. When I had the segue it just looked bad. – Waffles Mar 30 '16 at 00:54
  • Ooooh I see, so you're doing this with a tabViewController. I wish I could help more, but I've not dealt with tabViewControllers too much. Much luck! – blake_oistad Mar 30 '16 at 01:09