In this tutorial, we create 2 UIViewController With 1-1 UIButtons and Embed UINavigationController. After that, we create Custom Segue, and send data to SecondViewController; finally we set the UnWindSegue too. This tutorial is a Basic Settings tutorial, which made IOS 8 and Xcode 6.
1.2. Create SecondViewController class
Right Click and choose New File:
Choose Cocoa Touch Class
Add Name: SecondViewControler , and select Type: UIViewController.
1.3. Create SecondViewController on Main Storyboard, using Simulated Metrics
Add new ViewController (drag &drop from right side objects), and in Attributed Inspector switch Simulated Metrics Size from Inferred to iPhone device screen size. Now you can see controllers, and you can work with them.
Set Custom Class name to “SecondViewController” like the h and m file name.
Set Identity Storyboard ID
If you are using Segue later, you can refer to this name when you would like to say that from which or to which storyboard comes or goes the Segue.
1.4. Create Buttons on ViewController
Add button to the ViewController, click inside, enter the name. Click on "show the Assistant editor". Check, the file which appears (Automatic - ViewController or SecondViewController which one active on Storyboard - (click on it)).
Drag the button: with press cmd and drag into the h file below the @interface line. Select Type: UIButton, and add Name: CustomSegueButton.
Do the same with the SecondViewController and name the button as CustomUnwindSegueButton.
2.1. Ctrl-drag the CustomSegueButton to the SecondViewController.
After drag, int the list select Show.
2.2. Click left side bottom on the Show Document Outline button, and click on the Segue.
2.3. Click right side on the Show Attribute Inspector button.
And add the Segue Identifier name: CustomSeguetoSecondView, after that just click Enter.
If we would like to send data (string, number color settings…) from one ViewController to another one, and create a complex Application, it will be necessary.
3.1. Click on the ViewController, then Editor menu and select Navigation Controller.
3.2. Change Simulated Metrics Size property from Inferred to one of the iPhone device screens.
4.1. Import SecondviewController.h file in ViewController.m file.
4.2. Do in SecondViewController.h: create NSString *colorstring
4.3. In ViewController.m: create PrepareForSegue code, which prepares data to send.
You can prepare more Segue connections to more different ViewControllers. So you should use here the Segue Identifier name to tell which one send which data to where.
4.4. In SecondViewController.m: in viewDidLoad: change background color of the View.
Synthesize the colorString and create if statement, if colorString is equal to Purple, the view backgroundColor set to UIColor purple color.
Just click on Play button.
6.1. Do in ViewController.m: Create unwind code
6.2. Do on SecondView on Storyboard: Ctrl-drag the CustomUnwindSegueButton to the Exit and select “unwindfromSecondView”.
6.3. Add code to UnwindSegue to change the first ViewController background.
Just click on Play button.
To do the customization on segues click to the next post Custom Segue and Custom Unwind Segue with Animations using Navigation Controller - Part 2/2!
If you would like to be notified of my new solutions, please subscribe to my Newsletter or my youtube channel and/ or follow me on twitter! Check Footer section for these opportunities!