3

Below is an example of using initWithNibName with separate xib views:

TerminalViewController *ctrl = [[TerminalViewController alloc]
    initWithNibName:@"ControllerView" bundle:[NSBundle mainBundle]];
ctrl.appDelegate = self;
viewCtrl = ctrl;

However i need to implement it with a storyboard UI layout. For 'initWithNibName' how can i point to a View in my storyboard:

i.e. :

    TerminalViewController *ctrl = [[TerminalViewController alloc]     
    initWithNibName:@"STORYBOARD.ControllerView" bundle:[NSBundle mainBundle]];
    ctrl.appDelegate = self;

Any help is much appreciated. Thanks, Dave

user1845029
  • 995
  • 2
  • 10
  • 18

3 Answers3

14

You can give the controller an Identifier in the storyboard and then use this...

[self.storyBoard instantiateViewControllerWithIdentifier:@"TheIdentifier"];

Just to add to this...

When creating a UIViewController subclass from a xib file. If you have a class called MyViewController and a xib called MyViewController.xib then all you need to do is...

MyViewController *controller = [[MyViewController alloc] init];

The system will then look for a xib file called MyViewController.xib and use that to init the object and only fallback to doing it in code if the xib file doesn't exist.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
4

get storyboard instance with name of storyboard and set identifier to all scene and get the instance

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    MyNewViewController *myVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:@"myViewCont"];
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
2
UIStoryboard *stryBoard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
TerminalViewController *ctrl = [stryBoard instantiateViewControllerWithIdentifier:@"ControllerView"];
shanegao
  • 3,562
  • 1
  • 18
  • 21