16

I have some UIViewControllers from my old iOS4 project, they are using .xib, created in interface builder.

My new project, built for iOS5, uses storyboards.

I'm trying to add a UIViewController to the storyboard, but have it use a custom XIB that I already have. I've set the controller's identity in the indentity inspector (in interface builder), but am not sure how to ask that controller to load a custom .xib.

Any help is appreciated!

PS. Up to date I was able to get around this by creating a "wrapper" class for the storyboard purposes, and have that class have another UIViewController. But this kinda defeats the whole point of a storyboard.

Alex Stone
  • 46,408
  • 55
  • 231
  • 407

3 Answers3

19

You could copy the contents of the xib into the storyboard and then instantiate it using:

- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier

after setting the identifier on it. If you need the instance of the storyboard you can get it this way:

[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
Philippe Sabourin
  • 8,066
  • 3
  • 31
  • 46
  • Isn't it simpler to just copy .xib contents to his main storyboard file? – LordTwaroog Jan 02 '12 at 23:15
  • Yeah that's what I was telling him to do. Note that you can also get the storyboard from any UIViewController from the storyboard property. – Philippe Sabourin Jan 02 '12 at 23:19
  • After messing with wrappers and the order of viewDidLoad kind of crap, I'm happy to just copy the interface over and manually hook it up, even though this is what I was hoping to avoid. – Alex Stone Jan 03 '12 at 01:16
1

Mike K's answer is false.

While mixing XIBs and Storyboards doesn't really solve Alex's problem, it is quite possible to do within the same project.

See: https://stackoverflow.com/a/8516479/1309238 re: loading a second storyboard.

I'm not sure if including a "Main Storyboard" in your Target Summary is advisable if you plan to do this, but if you've loaded a XIB instead of a storyboard to begin with, you can modify the code linked above to load the storyboard after the XIB.

I'm not sure if you can jump into the middle of a storyboard from a XIB, which may have been what Mike meant.

Community
  • 1
  • 1
Kevin
  • 1,132
  • 2
  • 13
  • 24
-12

You cannot mix xibs and storyboards in your project -- it's one of the other, I'm afraid.

Ivan
  • 10,052
  • 12
  • 47
  • 78
Mike K
  • 2,227
  • 1
  • 12
  • 6