Reputation: 849
Hey I'm trying to open a view controller that is designed using a xib interface file. I am using the following lines of code to generate the controller from within a view controller created as a storyboard component.
YourViewController *viewController [[YourViewControlleralloc] initWithNibName:@"ViewControllerName" bundle:nil];
[self presentViewController:viewController animated:YES completion:nil];
I have never set up a view controller with a .xib before nor have I ever linked to one via storyboard so anything could be wrong. Here is the error I am getting when I try to present the view.
2013-05-17 13:06:45.120 Coffee[8991:907] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "PeekPagedScrollViewController" nib but the view outlet was not set.'
Upvotes: 0
Views: 716
Reputation: 5685
Set the Storyboard view controller custom class to your class name (the one your xib is also referencing), then in that same class, simply override initWithCoder
with:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [[super initWithCoder:aDecoder] initWithNibName:@"YourCustomViewControllerXibsName" bundle:nil];
if( self ) {
}
return self;
}
This will enable you to design layout and segue transitions in Storyboard, but design your layout in a standalone nib file.
Storyboard will handle instantiation, but when initWithCoder:
is called, initWithNibName:
will be the method that instantiates self
via the xib.
Upvotes: 0
Reputation: 849
It was connected properly I had just forgotten to declare an initWithNibName method and therefore it crashed when I called it from storyboard. Silly mistake but thanks for all the great feedback @matt
Upvotes: 0
Reputation: 535989
Set the File's Owner in the .xib to the class of your view controller (perhaps it is called PeekPagedScrollViewController).
Then connect its view
outlet to the main view in the .xib file.
Upvotes: 1