How to segue across iOS Navigation Controller programmatically using Swift?
<p>My question is very much like these two:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/27604192/ios-how-to-segue-programmatically-using-swift">IOS - How to segue programmatically using swift</a></li>
<li><a href="https://stackoverflow.com/questions/26456989/how-do-i-create-a-segue-that-can-be-called-from-a-button-that-is-created-program">How do I create a segue that can be called from a button that is created programmatically?</a></li>
</ul>
<p>EXCEPT that my segue is to a Navigation Controller, like this: <code>Main-&gt;NC-&gt;VC2&gt;VC3</code>.</p>
<p>The segue from Main to VC2 works fine when I trigger it with a button in my first view controller. It does not work when the segue is called by code.  I need to have the segue triggered automatically in response to certain conditions determined by the code in Main.</p>
<p>When the button is linked to a function coded in Main, it still works.  Code in the button function definition runs and the segue occurs. When I try to trigger the segue in the code for the function, using</p>
<pre><code>performSegueWithIdentifier(&quot;showHelp&quot;, sender: nil)
</code></pre>
<p>or</p>
<pre><code>performSegueWithIdentifier(&quot;showHelp&quot;, sender: self)
</code></pre>
<p>I get an error:</p>
<blockquote>
<p>Warning: Attempt to present &lt;UINavigationController: 0x7fc8e1043000&gt; on &lt;myApp.Main: 0x7fc8e0d17b10&gt; whose view is not in the window hierarchy!</p>
</blockquote>
<p>The button continues to trigger the segue, despite the warning, but not when the button's function is called by other code.</p>