Loaded nib but the 'view' outlet was not set

277,562

Solution 1

The View Identity - Class Identity was not set. After setting it to the appropriate class, the issue was resolved.

Solution 2

Here's what worked for me:

  • Open the XIB file causing problems
  • Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)
  • If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar. This will show the right-hand sidebar
  • In the right-hand sidebar, click on the fourth tab--the one that looks a bit like a newspaper
  • Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view. If not, enter it
  • In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it
  • You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline
  • Save the xib and re-run

Solution 3

This is Josh Justice proposal, but in a graphical way (pictures are mine):

  1. Select File owner
  2. On right hand side panel select custom class.
  3. Enter the custom class name

enter image description here

  1. On right hand side panel select oultets
  2. Drag view outlet to view component

enter image description here

Finally the View Controller is instantiated with the rolling code:

        PTFilterUserVC *aFilterUserVC = [[PTFilterUserVC alloc] initWithNibName:@"FilterVC" bundle:nil];

        //OPTIONAL.This is how 'I' am interested in present the view controller.
        [self.navigationController pushViewController:aFilterUserVC animated:YES];

Solution 4

I can generally fix it by remaking the connection between File's Owner and the view. Control-drag from the File's owner to your View (in IB) and select view from the pop-up menu.

Solution 5

Are you sure you have a UIView (or subclass) assigned to the "view" property of yourViewController?

Right click on "File Owner" in the left pane of the xib for yourViewController and verify that the "view" outlet is set. If not, set it to a view!

this will definetly fix the Issue

Share:
277,562
John
Author by

John

Updated on June 21, 2021

Comments

  • John
    John about 3 years

    I added a new nib file to my project, and tried to load it.

    However, when I click on the toolbar icon that is supposed to take me to the view that I created, I get an NSInternalInconsistencyException with the message:

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

    So I opened up my nib file, and I see for the view that there are no referencing outlets set. However, I try to click and drag the circle for "new referencing outlet" to File's Owner, but it won't let me...what do I need to do to get my view to display?

  • Apoc
    Apoc over 8 years
    I faced this issue on cocoa too and as long as the view wasn't loaded / added to the view hierarchy, all view outlets were NIL. After calling addSubview or something similar all outlets were connected. The funny part of my story was that po viewcontroller.view.subviews showed the missing objects.
  • PeiweiChen
    PeiweiChen about 8 years
    This solution is no longer working in Xcode 7.3 as of step 4&5. Instead, in interface builder, Control-drag from the File's owner to your View .
  • Alex
    Alex over 6 years
    Thank you so much. I was restructuring my views (embedding a table view within a view) and this helped me realize the view outlet was set incorrectly to the child table view I had moved.
  • Mansuu....
    Mansuu.... over 6 years
    Hi @John, I have done this but still getting this exception.
  • William T. Mallard
    William T. Mallard over 6 years
    Didn't work for me (no outlets section in the connection inspector, thus no "view" under outlets to connect to), but +1 for the effort you put into your answer. :)
  • Cristian Holdunu
    Cristian Holdunu about 6 years
    this should be the accepted answer. I was missing the point I have to associate also the view object to the main XIB view. Thanks.
  • josef
    josef about 6 years
    If you dont see "view" in the outlets you can also ctlr-drag from files owner to the view on the storyboard. A contextual menu should appear with a "view" option
  • BharathRao
    BharathRao about 6 years
    Thanks Javier Calatrava Llavería...helped me a lot after striking my head for an hour!!!
  • sark9012
    sark9012 about 6 years
    Clear, concise answer.
  • Bruno Sosa Fast Tag
    Bruno Sosa Fast Tag about 6 years
    un exito muchas gracias
  • user2319066
    user2319066 about 5 years
    @WilliamT.Mallard I have the same behavior. MyViewController is a subclass of subclass of UIViewController and there is no view under "Outlets". If I subclass MyViewController direct from UIViewController the view appears unter "Outlets". Magic or bug of Xcode.
  • Roman
    Roman almost 5 years
    Awesome. Thank you so much. This should be an accepted answer!
  • Lightness Races in Orbit
    Lightness Races in Orbit over 4 years
    @1800INFORMATION Please don't copy parts of answers into other answers. That is not fair.
  • 1800 INFORMATION
    1800 INFORMATION over 4 years
    @LightnessRacesinOrbit why not? if it makes the answer better then I think that's better for everyone. Kind of hilarious that you reverted a change I made 3 years ago just saying
  • Lightness Races in Orbit
    Lightness Races in Orbit over 4 years
    @1800INFORMATION The information exists elsewhere on the same page. Copying it into someone else's answer without clearly displaying attribution is not only pointless, but it is also unacceptable. We do not need to merge all the answers into one - the model is to have multiple answers with their own angles that you can vote on for the best. Doesn't matter how long ago it happened.
  • 1800 INFORMATION
    1800 INFORMATION over 4 years
    @LightnessRacesinOrbit good job making the top answer worse for everyone. Seems about right for SO these days
  • Lightness Races in Orbit
    Lightness Races in Orbit over 4 years
    @1800INFORMATION Sigh. Way to not get it.
  • Tamás Sengel
    Tamás Sengel about 4 years
    Still a bug in 2020.
  • hamada147
    hamada147 about 4 years
    I missed the 5th step
  • Habie Smart
    Habie Smart over 3 years
    Thanks Alot sir. I hope you always in health, sir @Javier Calatrava Llavería!