Segueing with a reusable table view

50 Views Asked by At

I am working on a directory listing application. Specifically, the app I am working on is called iEngineering. It would probably be best to drive home the purpose of my question if you download or look at the application on the AppStore. It is available for free. I would like to use one view controller with a table view to navigate to a similar view controller with table view. For example, selecting “Chemical Engineering” transitions/segues to a new screen with a new listing that displays sub categories within chemical engineering. Currently, my project requires two view controllers with table views for this process but I would like to condense it down into one single view controller with table view. Thank you all for your time and any guidance you may be able to offer me :)

1

There are 1 best solutions below

3
On

You only need the firstVC with a datasource array for the table , then when you select a category , instantiate a vc from that vc and send the array to it something like this

Inside ( didSelectRowAt ) of that SameVC

let vc = self.storyboard.,,,,,,,   as! SameVC
vc.arr = arr.subCategory // set the sub to the new table
self.navigationController?.push/////   // push not segue

Sure you will check if there is a content inside arr.subCategory before doing this as there will be leaf categories

Note: arr and subCategory are of same data type as it's a nested process