1

I have a storyboard view embedded in a navigation controller that displays a record from a database along with a link to view a related record. The related record needs to use the same view to display its data while still maintaining a navigation stack so the user can go back to the previous record. Keeping in mind that some data needs to be passed to the new viewController and the UI is composed of a tableView with each element in a row, how can this segue be accomplished?

Below is the view. If possible, please respond with any sample code in Swift. enter image description here

Wez
  • 10,267
  • 5
  • 48
  • 63
Michael Voccola
  • 1,767
  • 6
  • 19
  • 46

2 Answers2

2

With some inspiration from this answer and guidance by @Jassi, here is the final product:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let vc = storyboard?.instantiateViewControllerWithIdentifier("inventoryItemDetail") as InventoryDetail
    vc.fmRecordId = item["inContainerRecordId"]! //this is the data which will be passed to the new vc
    self.navigationController?.pushViewController(vc, animated: true)
}
Community
  • 1
  • 1
Michael Voccola
  • 1,767
  • 6
  • 19
  • 46
1

An idea-

Give the view controller an identifier. And override the below function.

prepareForSegue

In that function instantiate the view controller using the identifier you have and then pass the necessary data to that controller. And push it on navigation controller.

I hope it will work.

Jassi
  • 517
  • 7
  • 21