Perform a parent segue from the embedded view controller

sports picture sports · Jun 3, 2015 · Viewed 8.6k times · Source

I have this:

  • MyTableViewController (inherits from UITableViewController)

    • It has a dynamic tableview with a few cells (foo, bar, qux)

  • MyViewController (inherits from UIViewController)

    • There are some "show" segues from this controller to other view controllers
    • It has a UIContainerView that embeds MyTableViewController

A picture speaks a thousand words:

embedded uitableviewcontroller

When a certain cell is selected, I want to perform a segue of the parent view (MyViewController)

  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
         if (indexPath.section == 1 && indexPath.row == 1) {
                self.WHAT.performSegueWithIdentifier("someShowSegue1", sender: self)
         }
  }

Is it possible? what should I use in «WHAT»?

Answer

Zaphod picture Zaphod · Jun 3, 2015

In the prepareForSegue: for your embedded segue set the viewController in a new property in your tableViewController, let's name it parentController. And then you'll have just to call self.parentController.performSegueWithIdentifier().

EDIT: But first of all, maybe you can use the existing parentViewController if it contains the embedding view controller.