iphonemaclover iphonemaclover - 2 months ago 6x
Objective-C Question

Call Xib Class from Storyboard

I have a storyboard based project

I need to call a UIViewController class which is Xib based.

how can i call Xib class from storyboard and vice-versa?


I have 3 controllers.ViewController and ThirdViewController in Storybboard.SecondViewController is XIB part.

First I call XIB from Storyboard


#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()


@implementation ViewController 

- (IBAction)actionGoXIB:(id)sender
  SecondViewController *secondVC = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
  [self.navigationController pushViewController:secondVC animated:YES];

Now I call Stoyboard from XIB

If you want to acheive this, first Go to Storyboard Click ThirdViewController

Click->Identity Inspector

Then Click -> Identity

Now Set the Storyboard ID to ThirdViewController in the Identity section

See the screenshots below

enter image description here enter image description here


#import "SecondViewController.h"
#import "ThirdViewController.h"

@interface SecondViewController ()


@implementation SecondViewController

- (IBAction)actionGoStoryboard:(id)sender
  UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  ThirdViewController *thirdVC = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ThirdViewController"];
  [self.navigationController pushViewController:thirdVC animated:YES];
  // [self presentViewController:thirdVC animated:YES completion:nil];