Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Simply grab a reference to the target view controller in <code>prepareForSegue:</code> method and pass any objects you need to there. Here's an example...</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Make sure your segue name in storyboard is the same as this line if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"]) { // Get reference to the destination view controller YourViewController *vc = [segue destinationViewController]; // Pass any objects to the view controller here, like... [vc setMyObjectHere:object]; } } </code></pre> <p>REVISION: You can also use <code>performSegueWithIdentifier:sender:</code> method to activate the transition to a new view based on a selection or button press. </p> <p>For instance, consider I had two view controllers. The first contains three buttons and the second needs to know which of those buttons has been pressed before the transition. You could wire the buttons up to an <code>IBAction</code> in your code which uses <code>performSegueWithIdentifier:</code> method, like this...</p> <pre><code>// When any of my buttons are pressed, push the next view - (IBAction)buttonPressed:(id)sender { [self performSegueWithIdentifier:@"MySegue" sender:sender]; } // This will get called too before the view appears - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"MySegue"]) { // Get destination view SecondView *vc = [segue destinationViewController]; // Get button tag number (or do whatever you need to do here, based on your object NSInteger tagIndex = [(UIButton *)sender tag]; // Pass the information to your destination view [vc setSelectedButton:tagIndex]; } } </code></pre> <p>EDIT: The demo application I originally attached is now six years old, so I've removed it to avoid any confusion.</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