11
votes

This is not the same situation as the multitude of other similar questions here.

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the GameView nib but the view outlet was not set.'

You might be thinking "do as it says, connect the File's Owner to the View in IB!". But the thing is, I don't even HAVE a GameView.xib in my project or even in the project directory.

I do have a "GameViewController.m" and matching "GameViewController.xib" in my project. Using that GameViewController is what brings up this error, but I don't understand where it gets the idea to try and load "GameView.xib". Shouldn't it use "GameViewController.xib" instead?


If I grep my project directory, I do see it referenced from "UserInterfaceState.xcuserstate".

<string>file://localhost/Users/bemmu/Dropbox/b2/iphone/ValleyStory/ValleyStory/GameView.xib</string>

This mentioned file does not exist. I might have had a file with that name before and renamed/deleted it, but it's not being referenced to from anywhere that I can see in IB.

Did I manage to confuse xcode?

12

12 Answers

20
votes

My solution was a little different.

  1. Click on the xib in interface builder
  2. Select File's Owner on the left
  3. Open the File's Owner's connections inspector
  4. If the view property isn't yet wired, control-drag it to the view icon (under the file's owner and first responder icons).
5
votes

Check any nib files you're using (like MainWindow.xib). If you are loading GameViewController from a nib, check the file it's loading from (under the info tab in the inspector). Make sure it's set to "GameViewController" and not "GameView".

5
votes

I had this issue as well, but had to solve it a different way. Basically, I have a view controller name MainViewController, which has a xib named MainViewController.xib. This nib has it's view property set to the File Owner which was MainViewController.

I also made a MainView.xib that contained a view that was going to be programmatically added to the view defined in MainViewController.xib and it's view. It basically encapsulated an internal view that would be in the MainViewController.xib's view, and also had it's File Owner set to MainViewController.

So basically, I wanted MainViewController.xib to load as the nib for the MainViewController object, and inside MainViewController, at some later point, I would add the internal view specified by MainView.xib.

A couple issues arose:

1.) I found in the Apple docs that when loading a view controller via storyboard or nib:

"If the view controller class name ends with the word “Controller”, as in MyViewController, it looks for a nib file whose name matches the class name without the word “Controller”, as in MyView.nib.

It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is MyViewController, it looks for a MyViewController.nib file."

Therefore, you cannot have a nib called MainView.xib if you also have a nib called MainViewController and want MainViewController.xib to be the primary nib for MainViewController.

2.) Even if you delete MainView.xib or rename it to something else (MainInternalView.xib in this case), you MUST delete / clean your iOS simulator as the old nib file (MainView.xib) will still remain in the application. It doesn't overwrite the whole application package when you rebuild / rerun your application.

If you don't want to reset your content settings (perhaps you have some data you want to preserve), then right-click on your application in your iOS Simulator folder, Show Package Contents, find MainView.nib, and delete it. Xcode will NOT do this automatically for you when you rebuild, so we need to manually remove the old nib.

Overall, don't make nibs named MainViewController and MainView, i.e. nibs with the same prefix. Call MainView.xib something else, like MainInternalView.xib.

2
votes

I recently solved this issue. Make sure you back up your project before following the steps given here (just in case). These steps solved my issue

  1. Quit Xcode
  2. Navigate to UserInterfaceState.xcuserstate located at .xcodeproj/project.xcworkspace/xcuserdata/<username>.xcuserdata and delete the file.
  3. Reopen Xcode. Xcode will create a new UserInterfaceState.xcuserstate which will be clean.
1
votes

In my case, I was not using a xib at all. I needed remove the .m file from Build Phases > Compile Sources and added it back.

0
votes

Given you referenced it previously it sounds like xcode hasn't ackowledged it no longer exists. From the Product menu select "Clean" and then "Build" hopefully this will get past the old reference for you.

0
votes

Face the same Problem, had to change the view's name in code:

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"WrongViewName" bundle:nil];

To

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"RightViewName" bundle:nil];
0
votes

I had multiple views, and by accident (I don't know how this happenned) but my background view didn't have a file owner, so for anyone else who has this problem in the future, make sure all your views have a file owner.

0
votes

I was gettint the same error then check the classname from interface builder and see that I typed the view controller class name at the custom class attribute.

0
votes

UIViewController searches for a nib with the same name as the controller when passed nil to initWithNibNamed:bundle: Check that the file name that you pass to the initializer is correct and exists!

For example:(e.g. [[CCVisitorsController alloc] initWithNibName:nil bundle:nil] then UIViewController tries to load nib with name CCVisitorsController as default.

If that file does not exist then the error you mentioned is thrown.

0
votes

I had this problem because I was doing something bad in

  • (id) initWithCoder:(NSCoder *) coder

which the NIB loads.

0
votes

In my case this error was produced by dumb mistake - I delete _view view dumb mistake