Lewis Seddon
Lewis Seddon

Reputation: 153

iOS Design: TableViews or Other?

I'm currently at a stage within my app design phase where I am totally stuck as to which method would be more suitable, tableView or something else?

My app currently pulls large data sets into a CoreData model, some of these objects have objects related to them.

I wish to display a list of the topmost level object (easy enough, just bang it into a dynamic tableView). However, this is where my problem lies, when I click an object in this first tableView, I want another tableView to appear to it's side with a list of all it's related objector "children". Then I want the same to happen on these children objects once clicked.

I have attached a screen cap of how I wish it to look once a new tableView is created, this is currently created on viewLoad, which is incorrect for my specification as it loads all the children of all the objects:

Sensitive Info Censored, target layout

Would this be best achieved using multiple tableView in the same storyBoard, or is there another method I am overlooking which would be more suitable?

Thanks!

Upvotes: 0

Views: 76

Answers (1)

Rhuari Glen
Rhuari Glen

Reputation: 507

The easiest, and most "Apple" way would be to push to a new UITableViewController when a cell is tapped on. In the func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) function, you could use the indexPath.row value to retrieve the object and then pass this through to the next ViewController for rendering within another UITableView.

As you have mentioned that you may be handling a lot of child data, the way to handle this would be to create a generic subclass of UITableViewController, we'll call it GenericTableViewController, with a property named dataArray to hold your child data. In the func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) function, instantiate a GenericTableViewController, assign the selected object's children to dataArray and push the new GenericTableViewController onto the navigation stack. This will allow you to repeat this for as long as you may need, depending on how many child objects you have.

Your UIStoryBoard would consist of one UITableViewController embedded within a UINavigationController. This UITableViewController would handle the presentation of the GenericTableViewController. Then in turn, each GenericTableViewController would handle the presentation of another GenericTableViewController.

Upvotes: 1

Related Questions