Monday, September 9, 2013

Attach Multiple View Controllers in a Single Storyboard

I have taken 2 UIViewControllers in a single StoryBoard like in above pic.

First View Controller (with White background in above pic) is linked with ViewController.h and Second View Controller (with Red color background) is linked with SecondVCViewController.h

Linking is done by Selecting Identity Inspector as in below pic

               ^                                                                                                 ^
For First View Controller                                                  For Second View Controller

Note: Mention Other Storyboard ID(s) in Linkage, so that linkage name could identified by below code.

Now define Button's IBAction in its respected class file.

1. Now for First View Controller action

- (IBAction)onTapSecondViewAppearBtn:(id)sender {
    SecondVCViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondVCViewController"];
    [self presentViewController:svc animated:YES completion:nil];


2. Now for Second View Controller action, To remove the current View

- (IBAction)onTapFirstViewBtn:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];