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.
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 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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With