title: How do I create details for UITableViewCell while jumping to that detail after the button is clicked?
body: <p>I'm using <em>Xcode 8.2</em>, <em>Swift 3</em>, <em>iOS 10</em>.  I realize the title may be a difficult to understand so let me explain what I'm trying to do.</p>
  
  <p>I have a <code>TabViewController</code> with three child <code>ViewControllers</code>, each with their own <code>NavigationController</code> and other stuff after that.  One such tab is shown below (Tab 1).  This is a <code>TableViewController</code> on which I'm showing my custom <code>TableView</code> <em>cells</em> with information.</p>
  
  <p><a href="https://i.stack.imgur.com/CE2po.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CE2po.png" alt="enter image description here"></a></p>
  
  <p>On a different tab (e.g. Tab 2), I'm adding cells into Tab 1 on button click.  I have gotten this to work just fine.  Now, the behavior that I want is that when the user clicks that same button (on Tab 2), I want to add a cell (as before) but also add the details view of that cell and jump to that details view (instead of having to switch to Tab 1 and click the respective cell).  On this details view, I want there to be a <strong>Back</strong> button which will return me to Tab 1 which is where all the details views are accessed.  </p>
  
  <p>I have been trying to figure out the right way to achieve this behavior so any help would be greatly appreciated.  Thank you!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I made some edits based off of Winter's reply below.  However, I am still unable to "connect" the newly created <code>UIViewController</code> with a Table View cell.  </p>
  
  <p>I did the following:</p>
  
  <p>In Tab 2:</p>
  
  <pre><code>// this code is located in a function where I call to create a new custom cell in Tab 1.  
  
  //Switch to first tab
  tabBarController?.selectedIndex = 0
  
  //Show the detail view
  if let navigationController = tabBarController?.viewControllers?[0] as? UINavigationController {
      let detailViewController = UIViewController()
      detailViewController.view.backgroundColor = UIColor.red
      navigationController.pushViewController(detailViewController, animated: true)
  
      let tempNavVC = self.tabBarController?.viewControllers?[0] as! UINavigationController
      let resultsTab = tempNavVC.viewControllers[0] as! Tab1VC
      resultsTab.detailVCArray.append(detailViewController)
  }
  </code></pre>
  
  <p>In Tab 1:</p>
  
  <pre><code>// this is an array that holds the newly created view controllers passed in from Tab 2
  // when the user clicks on a cell, look up which cell it clicked on and display the view controller for that cell
  var detailVCArray = [UIViewController]()
  
  // called when a cell is clicked
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  
      let newChildVC = detailVCArray[indexPath.row]
      self.addChildViewController(newChildVC)
      self.present(newChildVC, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>When I run it, the code in Tab 2 successfully executes and I am presented with a new View Controller with a red background.  However, if I click the Table View cell, it errors out:</p>
  
  <blockquote>
    <p>'NSInvalidArgumentException', reason: 'Application tried to present
    modally an active controller</p>
  </blockquote>
  
  <p>instead of segueing to the same red View Controller.</p>
  
  <p>I realize this is probably a really dumb way to do it but I can't think of anything else.  </p>
  
  <p>At the end of the day, I want my Tab 2 to create a Table View cell in Tab 1 that contains some View Controller with details and "transition" me to those details.  </p>