Create the storyboard shown in the figure below. RedViewController pushes to YellowViewController, YellowViewController pushes to BlueViewController, and BlueViewController modal to GreenViewController. You can return RedViewController from YellowViewController and YellowViewController and RedViewController from BlueViewController. Of course, you can also go back to the BlueViewController from GreenViewController.
Back to the code. Since storyboard is used, the jump of push and model saves writing code, similarly, the jump of “return” also saves code.
RedViewController. M
– (IBAction)unwindSegueToRedViewController:(UIStoryboardSegue *)segue {
}
It’s important to note that the return value of this method must be an ibaction, and the argument must be a uistoryboardsegue. As for why, the following code will show.
Go back to your storyboard file and observe that the RedViewController scene has a green button below it (not because you wrote the code above, but because it’s always there).
Next, right click the exit button (green button), will appear just write method unwindseguetoredviewcontroller:
Select this method and drag and drop to the Back RedVC button on the YellowViewController.
After letting go, an Action prompt appears near Back RedVC and is selected. In this way, when you click the Back Red VC button on the YellowViewController, it will jump back to the Red View Controller. Let me compile it. There’s no problem with insurance. Run the program.
Instructions required:
1. If you like from yellowviewcontroller returns to redviewcontroller, then unwind segue associated methods must be stated in redviewcontroller again, that is the example of – (inaction) unwindtoredviewcontroller (segue uistoryboardsegue *); Note the parameters and return points, and the method name is arbitrary.
2. Right click on the exit button of redviewcontroller (green button) to show the method that unwind segue can associate with, and then go to the button of yellowviewcontroller.
Similarly, the BlueViewController can be returned to the Implementation of The YellowViewController.
In YellowViewoController. M
– (IBAction)unwindToYellowViewController:(UIStoryboardSegue *)segue {
}
Right-click the Exit button of The YellowViewController to associate BlueviewControler’s Back YellowVC button.
Also need to realize from the immediate return to redviewcontroller blueviewcontroller, selected redviewcontroller exit button, select the button on the blueviewcontroller unwindtoredviewcontroller associated.
Compile it, no problem, run it, get a feel for it.
Either the YellowViewController or the BlueViewController can be returned to the RedViewController, at which point you need to make a judgment to see where the return is coming from.
- (IBAction)unwindSegueToRedViewController:(UIStoryboardSegue *)segue {
UIViewController *sourceViewController = segue.sourceViewController;
if ([sourceViewController isKindOfClass:[YellowViewController class]]) {
NSLog(@"from yellow vc");
}
else if ([sourceViewController isKindOfClass:[BlueViewController class]]) {
NSLog(@"from blue vc");
}
}
And that’s why the argument to a method is a segue, where you get the source View Controller.
Now when you try push, the same thing with modal, you present the GreenViewController from the BlueviewController in modal mode.
To return, you need to write the method associated with the unwind segue in the BlueviewController:
– (IBAction)unwindToBlueViewController:(UIStoryboardSegue *)segue {
}
Associated unwindtoblueviewcontroller methods on the corresponding button.
At this point, I’m done with “back” in my storyboard, and I spend most of my time dragging and dropping controls without writing the relevant pop dismiss method at all. That’s one of the strengths of storyboard.
Is it possible to implement it in code?You can.
Select GreenViewController Scene in your storyboard, and on the left you can see the representation of the unwind segue, kind of like the DNA sequence yes, once you select it, the only representation that defines it is the greenUnwind
In greenviewcontroller. M
Method associated with back Code button:
- (IBAction)backCodeBtnTapped:(id)sender {
[self performSegueWithIdentifier:@"greenUnwind" sender:self];
}
Compile, there are no errors, the program.
Program all code.
Read More:
- About “undefined reference to” when compiling uboot__ aeabi_ unwind_ cpp_ The solution of “PR0 ‘”
- Summary of database
- Summary of errors in installing texlive2017
- Anaconda + vscode usage problem summary
- IOS — solving the problem of reading from private effective user settings
- Ffmpeg (libx264) compiling for IOS
- Summary of problems encountered by CodeBlocks + OpenGL
- UIStackView before iOS 9.0
- Summary of MySQL error code
- UDID and UUID in IOS development
- Summary of OpenGL simple solar system simulation
- Summary of common runtimeException exceptions
- ios Cocoa error 4097
- Problem solving of IOS apple mach-o linker error group
- Summary of common errors in angularjs
- OpenGL learning summary (1)
- Error:kCFStreamErrorCodeKey=-2102 Domain=kCFErrorDomainCFNetwork Code=-1001 – iOS
- JavaScript summary: the difference between typeof and instanceof, and Object.prototype.toString() method
- IOS swift error
- IOS error: linker command failed with exit code 1 solution