Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The above code in your question is fine. I know you were asking about how to do this without a button, but the problem with your demonstration was that you used a button, but didn't properly hook it up to the <code>IBAction</code>. Your <code>goNext</code> should be defined in your .h as:</p> <pre><code>- (IBAction)goNext:(id)sender; </code></pre> <p>And the implementation should be:</p> <pre><code>- (IBAction)goNext:(id)sender { UIViewController *vc=[[self storyboard] instantiateViewControllerWithIdentifier:@"10"]; [self.navigationController pushViewController:vc animated:YES]; } </code></pre> <p>I presume you created that <code>IBAction</code> manually. In the future it's worth noting that if you <kbd>control</kbd>-drag (or right-click drag) from the button down to the assistant editor file, you can automate the creation of your <code>IBAction</code> interfaces, and this sort of error won't happen:</p> <p><img src="https://i.stack.imgur.com/aVnmu.png" alt="automate creation of IBAction"></p> <hr> <p>As an aside, I personally like to use a segue instead, so I first define the push segue between the view controllers themselves. In Xcode 6, one would <kbd>control</kbd>-drag from the view controller icon above the scene to the destination scene:</p> <p><img src="https://i.stack.imgur.com/Jupss.png" alt="create segue xcode 6"></p> <p>In Xcode versions prior to 6, one would <kbd>control</kbd>-drag from the view controller icon in the bar below the scene:</p> <p><img src="https://i.stack.imgur.com/P32bS.png" alt="create segue"></p> <p>I then select the segue in Interface Builder and give it a "storyboard identifier" (in this example, I called it <code>pushTo10</code>):</p> <p><img src="https://i.stack.imgur.com/at0Nn.png" alt="specify segue id"></p> <p>I then have my <code>goNext</code> execute that segue, rather than manually invoking <code>pushViewController</code>:</p> <pre><code>- (IBAction)goNext:(id)sender { [self performSegueWithIdentifier:@"pushTo10" sender:self]; } </code></pre> <p>The advantage of that is that my storyboard now visually represents the flow of my app (rather than appearing to have a scene floating out there) and graphical elements like the navigation bar are correctly represented in the storyboard. </p> <p>You don't have to do it this way, but it's another alternative to be aware of.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload