The unwind segue can be used as a fallback in the navigation controller, with Push,modal, and popover three effects. (Effects and direct use of the navigation controller are the same, but more powerful).
Assuming that a is the root controller of the navigation controller, and the controller has another B controller, under B there is a C controller, the level can also be more deep, from the deepest controller back to a
The unwind segue can be reached directly, and only a method like the following code needs to be created in a:
?
| 1 2 3 |
- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue {} |
Here is an example of a specific implementation:
The controller that created the above structure in storyboard Navigationcontroller's root controller is the red controller, red to green, green to blue is the way to use push (other ways can also be used in a uniform way, Otherwise Xcode will print a warning:2014-05-20 15:30:13.165 unwindsegues[1027:70b] warning:attempt to dismiss from view Controller < Uinavigationcontroller:0x8a57320> while a presentation or dismiss are in)
Red Controller puts a button (Go green), connect green controller with push, add two buttons to green controller go blue, unwind to Red, go Blue direct connection Blue control, add two buttons in blue controller (go to Green, go to Red), add the method in the corresponding implementation code
?
| 1 2 3 4 |
-(IBAction)unwindToRed:(UIStoryboardSegue *)segue { } |
After writing the method, connect the button in the green controller to the lower exit of the green controller and select the method added in the Red Controller code
Add a similar method to the green controller's code again
?
| 1 2 3 4 |
-(IBAction)unwindToGreen:(UIStoryboardSegue *)segue { } |
Connect each of the two buttons in the blue controller as described above.
Test code:
Run the program directly click the button test effect, you can complete directly from the blue controller to the red controller jump.
This functionality is implemented through code:
View this unwind segue in the property view, so that the direct call can achieve the same effect, but only in their own class to use the segue, that is, there is no commonality
[ self Span class= "PLN" > Performseguewithidentifier :@ " Unwindtoredsegueid " sender : self ;
The wording of the article may not be accurate, if necessary, can be directly read the original English:
http://stackoverflow.com/questions/12561735/ What-are-unwind-segues-for-and-how-do-you-use-them
May 20, 2014