Changes

Jump to: navigation, search

Using Xcode Storyboarding (iPhone iOS 5)

2 bytes added, 15:22, 3 November 2011
no edit summary
== Triggering a Storyboard Segue Programmatically ==
In addition to wiring up controls in scenes to trigger a segue it is also possible to initiate a preconfigured segue from within the application code. For the sake of an example, assume that when scene 2 is displayed we want to segue back to scene 1 if the device is turned upside down. Since there is no way to implement this within the storyboard canvas in Interface Builder the only option to trigger the segue is from within the code of the application. Segues are triggered from within code by calling the ''performSegueWithIdentifier:'' method of the UIViewController class. One of the arguments required by this method is the identifier of the segue to be performed. By default, segues created in storyboards are not given identifiers. The first step, therefore, is to assign an identifier to the segue that returns to scene 1 from scene 2. To achieve this, select the ''MainStoryboard.storyboard'' file in the project navigator and select the segue arrow for the scene 2 to scene 1 segue. Display the Identity Attribute Inspector panel (''View -> Utilities -> View Identity Attribute Inspector'') and enter the “SegueToScene1” in the Identifier text field.
Next, edit the Scene2ViewController.m file, scroll down to the ''shouldAutorotateToInterface-Orientation:'' method and modify it to trigger the segue when the device detects that it is upside down:

Navigation menu