-1

Let's say I have a tableView which has 20 rows inside containing data(e.g: contact names), and whenever any random row is tapped it shows another table view which contains contact name details , so far I have created 2 table views, one is for "contact name" and one is for "contact details" (only for one row yet )

but the problem is that If I keep creating ViewControllers for each row details, I will end up having 20 separate Controllers which makes storyBoard massive and messy, So I searched some good techniques to simplify this, but could not find the better approach yet.. . AnyOne, can suggest some out of their shelf or under the belts..? )

letsCode
  • 31
  • 7

2 Answers2

0

You don't have to create 20 ViewController, you need exactly 2. The first for the "Contact List" and the Second one for the Details. You simply use the prepareForSegue method passing one contact to the Detail ViewController where you then display its Data. You reuse the Detail ViewController for every Contact!

Prepare for Segue: Swift 3 - Prepare Segue

Deitsch
  • 1,610
  • 14
  • 28
0

you do not need to create separate controller in StoreyBoard for each item. What you need it's just create one controller and call performSegueWithIdentifier or call:

let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! SomeViewController
navigationController?.pushViewController(viewController, animated: true)
viewController.configure(yourDetails)

where configure(yourDetails)is your configuration methods, where you passing your details

Mike H
  • 487
  • 2
  • 13