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,555
  • 5
  • 49
  • 63
Michael Voccola
  • 1,827
  • 6
  • 20
  • 46
  • Please share your storyboard view image. – Jassi Mar 25 '15 at 16:24
  • @Jassi I have included a screenshot of the view. Do note that the button which will trigger the segue is a cell inside a table. – Michael Voccola Mar 25 '15 at 16:29
  • So this view controller is attached to a navigation controller ? Right? – Jassi Mar 25 '15 at 16:31
  • @Jassi Correct, the view is embedded in a navigation controller. It needs to segue to a new instance of itself, pass the new instance some data to display and allow the user to pop the view off the nav stack and return to the original instance. – Michael Voccola Mar 25 '15 at 16:32

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,827
  • 6
  • 20
  • 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
  • 537
  • 8
  • 21