Reputation: 171
My iOS 5-6 app is crashing after attempting to load a ViewController from a button pushed in one storyboard file (FifthViewController.storyboard) to a separate xib (WebViewController.xib). The exact error message: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "WebViewController" nib but the view outlet was not set.'
This error typically appears when view outlets have not been connected or ViewControllers have not been assigned a class. In WebViewController.xib, everything is connected, including the view (you cannot disconnect this, actually) and my web view. My ViewController's class is correctly labeled as WebViewContrller.
Here's my code:
WebViewController.h
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) NSURL *urlToLoad;
- (id)initWithURL:(NSURL *)url;
WebViewController.m
@synthesize webView, urlToLoad;
- (void)viewDidLoad {
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:urlToLoad]];
}
- (id)initWithURL:(NSURL *)url {
[self setUrlToLoad:url];
return self;
}
FifthViewController.m -- this is the VC from where a button is place that calls WebViewController
- (IBAction)pushedArts:(id)sender {
WebViewController *wvc = [[WebViewController alloc] initWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]];
[self presentModalViewController:wvc animated:YES];
}
The images show the connections within WebViewController.xib and its class. Any insights would be greatly appreciated. Thank you.
Upvotes: 2
Views: 3044
Reputation: 17143
Your -[WebViewController initWithURL:]
method should call [super initWithNibName:bundle:]
to properly initialize your view controller, including associating the proper nib, etc.
In general, if you write any initializer it has to (directly or indirectly) call the designated initializer of the superclass.
Upvotes: 2
Reputation: 18741
I think you need to check your nib file, because it is clear for me that the system could not locate your nib file, or the view outlet is not connected. Open your nib file, go to the last tab, and connect your view outlet, as the normal way you should connect other components
Upvotes: 0