Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone IOS5 Storyboard, how to load a UIViewController with a custom .xib file?

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.

like image 760
Alex Stone Avatar asked Jan 02 '12 22:01

Alex Stone


People also ask

How do you load a nib on a storyboard?

If you want to load the view from a nib in code you would just instantiate it directly using the same technique. All the subclass does is take the code to instantiate the view from a nib and put it in a hook for the storyboard to use.

How to create a class for view in Swift?

How can you create XIB for View? Open Xcode ▸ File ▸ New ▸ File ▸ Cocoa Touch class ▸ Add your class name ▸ Select UIView or subclass of UIView under Subclass of ▸ Select language ▸ Next ▸ Select target ▸ Create the source file under your project directory.


1 Answers

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];
like image 152
Philippe Sabourin Avatar answered Oct 24 '22 09:10

Philippe Sabourin