0

im new for iOS development right now. I want to make an application that shows tableviews from my array. I hold JSON data at a txt file on my server. I want to recieve them through Alamofire and populate my tableviewcells. Currently i can do it. There is a lot of guides about it. But i want to create new table when i click that cell. For example lets say this is my Json data;

   {
"fruits": [
    {
        "Vitamin": "Vitamin C",
        "Name": "Apple",
    }
    {
        "Vitamin": "Vitamin B",
        "Name": "Banana",
    }        {
        "Vitamin": "Vitamin D",
        "Name": "Watermelon",
    }        {
        "Vitamin": "Vitamin C",
        "Name": "Orange",
    }
    {
        "Vitamin": "Vitamin C",
        "Name": "Mandarin",
    }
] }

And with that json data i just want to create 3 tableviewcells which are Vitamin C, Vitamin B and Vitamin D. When i want to tap Vitamin C cell i want to see new tableview which holds Apple, Orange, Mandarin.

So what should i do for this? I guess at storyboard i need to create multiple controllers and multiple swift files for these? Should i parse the Json data and put them in different arrays? I'm open to all suggestions or any guide that i missed. Thank you all for your time

1 Answers1

0

I would create an object and create that when you read your JSON with Alamofire (use a Library like SwiftyJSON to get easy values from your JSON)

But you should change your json a little bit, like:

"fruits": [
{
    "Vitamin": "Vitamin C",
    "Fruits": ["Apple", "Orange", "Mandarin"]
}

So Vitamin C is your "key" and "Apple", "Orange", and "Mandarin" are you Array Values.

Now you should create an object, like:

class fruits {
   var vitamin: String!
   var inFruits: [String]!
}

Now you can add some fruit objects when you receive your values from your JSON. On your first TableViewController, just show the values from fruits, when you do:

 didSelectRowAtIndexPath

you should pass the inFruits String Array to your next ViewController, as shown here:

Sending data with Segue with Swift

Community
  • 1
  • 1
derdida
  • 14,784
  • 16
  • 90
  • 139