iOS - Storyboards

Advertisements


Introduction

Storyboards are introduced in iOS 5 and when we use storyboards our deployment target should be 5.0 or higher. Storyboards helps us visual create all the screens of the application along with their flow of screens under one interface MainStoryboard.storyboard. It also helps in reducing coding of pushing/presenting view controllers.

Steps Involved

1. Create a single view application and make sure that you select storyboard checkbox while creating the application.

2. Select MainStoryboard.storyboard where you can find single view controller. Now add one more view controller and update the view controllers as shown below.

iOS Tutorial

3. Now let connect both the view controllers. For this right click on the button name "show modal" and drag it to the right view controller in the left side view controller as shown below.

iOS Tutorial

4. Now select modal from the three options displayed as shown below.

iOS Tutorial

5. Update ViewController.h as follows.

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

-(IBAction)done:(UIStoryboardSegue *)seque;

@end

6. Update ViewController.m as follows.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];	
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)done:(UIStoryboardSegue *)seque{
    [self.navigationController popViewControllerAnimated:YES];
}

@end

7. Select MainStoryboard.storyboard and right click on the Exit button in the right side view controller select done and connect with back button as shown below.

iOS Tutorial

Output

Now when we run the application in iPhone device we'll get the following output.

iOS Tutorial

Now when we select show modal we will get the following output.

iOS Tutorial



Advertisements
Advertisements