Key Points When Setting Segues Directly
In learning to use Storyboarding both programmatically and directly, here are a few key points I’ve found.
When setting segues directly…
- If a button leads to a segue, CTRL-Drag it to the next View Controller. Distinctly name each segue in the Identifier field of the Inspector option in the Utilities tab!
- Each button that leads to segue will have its own ViewController that is created and pushed on top of the view stack.
- In your
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender implementation, use if statements to select the correct segue.identifier to send appropriate messages to your segue.destinationViewController object.
One key reason to set segues directly is if each segue has a unique UI. This way, you can fully customize each the UI of the view for each resulting segue.
Also, when you set the segue directly, you do not need to call
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
because this code is used when you have a button as a target-action to manually call execute the segue when pressed. However, when directly setting the segue in Storyboard, your buttons do not have target-actions, but rather direct segues (via CTRL-drag) to the next ViewController. Therefore, that connection will know to execute the segue.
Here are all of the if statements in
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender I was referring to: