2011-01-21 20:35 阅读 453


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?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

27条回答 默认 最新

  • 已采纳
    csdnceshi77 狐狸.fox 2011-01-25 21:03

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

    点赞 6 评论 复制链接分享
  • csdnceshi53 Lotus@ 2015-06-05 09:08

    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];
    点赞 28 评论 复制链接分享
  • weixin_41568110 七度&光 2011-06-18 11:43

    You guys are right, but as I'm a newcomer it took me a little while to figure out all the steps to do that. 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 third 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

    Custom class configuration

    • 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

    Custom class configuration

    • Save the xib and re-run
    点赞 22 评论 复制链接分享
  • csdnceshi52 妄徒之命 2012-10-25 01:04

    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.

    点赞 10 评论 复制链接分享
  • csdnceshi71 Memor.の 2016-04-22 10:23

    I had face the same problem while accidentally deleted xib reference and added it again.I just fixed by making connection between Files owner and the view.Also make sure that your FilesOwner's custom class is your expected viewController.

    点赞 10 评论 复制链接分享
  • csdnceshi70 笑故挽风 2014-03-13 16:58

    For me all the things stated here https://stackoverflow.com/a/6395750/939501 were true but still it was throwing error, reason was I created a View class with name ABCView and then deleted it later I added a view controller as ABCViewController so somehow it was referring to old ABCView in new view controller, I had to delete the ABCViewController and add a new one with different name that solved my issue.


    点赞 7 评论 复制链接分享
  • weixin_41568208 北城已荒凉 2015-12-17 07:09

    In my case , the designated initializer - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil in ***ViewController class was implemented so even if when I call other initializer to initialize the object ,the designated initializer will be called .

    So to resolve this problem checking wether the - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil is also a proper way.

    点赞 7 评论 复制链接分享
  • csdnceshi77 狐狸.fox 2018-02-21 23:03

    To anyone that is using an xib method to create a UIView and having this problem, you will notice that you won't have the "view" outlet under the connections inspector menu. But if you set the File's Owners custom class to a UIViewController and then you will see the "view" outlet, which you can just CMND connect an outlet to the CustomView.

    点赞 7 评论 复制链接分享
  • csdnceshi65 larry*wei 2012-05-04 02:16

    I had the same problem, but a slightly different solution was called for. The problem in this case was the class of the File Owner, rather than the class of the View. To set this, I had to click the "backwards play" icon in the lower left corner of the Interface Builder window, and options then appeared that isolated the characteristics of the File Owner, the First Responder, and the View. Clicking on the first one (a large transparent box), enabled me to then set its custom class as suggested above.

    点赞 6 评论 复制链接分享
  • csdnceshi63 elliott.david 2011-07-28 13:57

    Just spent more than hour trying to find out why my view property is not set in my view controller upon initiating it from nib. Remember to call "[super initWithNibName...]" inside your view controller's initWithNibName.

    点赞 4 评论 复制链接分享
  • csdnceshi59 ℙℕℤℝ 2012-06-21 00:49

    I just fixed this in mine. Large project, two files. One was "ReallyLargeNameView" and another was "ReallyLargeNameViewController"

    Based on the 2nd answer chosen above, I decided I should clean my build. Nada, but I was still suspect of XCode (as I have two identical classes, should abstract them but eh...) So one's working, one's not. File's owner names are so far as copy and pasted, outlets rehooked up, xCode rebooted, still nothing.

    So I delete the similar named class (which is a view). Soon, new error "outlet inside not hooked up" literally was "webView not key value" blah... basically saying "Visual Studio's better". Anyway... I erase the smaller named file, and bam, it works.

    XCode is confused by similar-named files. And the project is large enough to need rebooting a bit, that may be part of it.

    Wish I had a more technical answer than "XCode is confused", but well, xCode gets confused a lot at this point. Unconfused it the same way I'd help a little kid. It works now, :) Should benefit others if the above doesn't fix anything.

    Always remember to clean your builds (by deleting off the simulator too)

    点赞 4 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 2013-01-05 17:18

    I had the same problem, but a different solution was called for. The problem in this case was the class of the File Owner was not connected to xib file.

    点赞 4 评论 复制链接分享
  • csdnceshi61 derek5. 2013-07-05 19:54

    I had the same issue with XCode 4.6.3. I had started out with a couple files named MySettingsView.h and .m but deleted them in favor of MySettingsViewController.h, but despite trying most of the hints mentioned here, it still kept erroring with,

    2013-07-05 11:48:17.205 MyApp[39024:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MySettingsView" nib but the view outlet was not set.'

    It was evidently still "confused", trying to load MySettingsView.xib instead of MySettingsView Controller.xib. Maybe its "do what I mean" logic is too fancy.

    So I worked around the problem by hardcoding the NIB/XIB name in MySettingsViewController.m:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
        self = [super initWithNibName:@"MySettingsViewController" bundle:nibBundleOrNil];
    点赞 4 评论 复制链接分享
  • csdnceshi69 YaoRaoLov 2011-08-30 20:07

    My issue with this was caused by having a duplicate nib in the class folder that did not have the view set. xcode seemed to be choosing one nib for a build and then the other the next time I built the project. Just deleted the other one. Looks good. Doh!

    点赞 3 评论 复制链接分享
  • csdnceshi53 Lotus@ 2015-02-22 06:03

    I ran into something very similar tonight, with a Swift UIViewController subclass. In this case, none of the above fixes worked, but reordering my code a bit did. Net-net, having an extension to the subclass occur before the subclass's definition itself in the same file seems to confuse XCode, despite compiling fine; the fix was to place the extensions after the subclass's definition.

    I've posted the details in an answer to this similar question.

    点赞 3 评论 复制链接分享
  • weixin_41568127 ?yb? 2011-10-11 13:17

    I also had the same problem and my issue was that i added an other Localisation (English) to the ViewControllers nib so my App with the Localisation German could´t find the nib with the Localisation English!! Hope this helps anybody!

    点赞 2 评论 复制链接分享
  • csdnceshi58 Didn"t forge 2013-08-21 13:05

    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

    点赞 2 评论 复制链接分享
  • weixin_41568183 零零乙 2011-12-31 16:34

    For me, the problem was caused by calling initWithNibName:bundle:. I am using table view cells from a nib file to define entry forms that sit on tableViews. As I don't have a view, doesn't make sense to hook to one. Instead, if I call the initWithStyle: method instead, and from within there, I load the nib file, then things work as expected.

    点赞 1 评论 复制链接分享
  • csdnceshi64 游.程 2012-10-30 19:41

    Just had the same error in my project, but different reason. In my case I had an IBOutlet setup with the name "View" in my custom UITableViewController class. I knew "view" was special because that is a member of the base class, but I didn't think View (different case) would also be a problem. I guess some areas of Cocoa are not case-sensitive, and probably loading a xib is one of those areas. So I just renamed it to DefaultView and all is good now.

    点赞 评论 复制链接分享
  • csdnceshi53 Lotus@ 2012-11-26 09:34

    select the files owner and goto open the identity inspecter give the class name to which it corresponds to. If none of the above methods works and still you can't see the view outlet then give new referencing outlet Connection to the File's Owner then you can able to see the view outlet. Click on the view Outlet to make a connection between the View Outlet and File's owner. Run the Application this works fine.

    点赞 评论 复制链接分享
  • csdnceshi63 elliott.david 2013-03-21 22:02

    I'd like to second Stephen J. Some times X Code does just get confused. I just had an experience where I had played around with the UI a lot, and had added and deleted outlets quite a few times. The outlets just would not wire-up any more. I never did figure out a specific reason (I had tried all the solutions above), and I just had to delete the NIB and recreate it from scratch, and in fact had to use a different name for the NIB before it would work. (XCode 4.6.1) Wasted a couple of hours on that.

    点赞 评论 复制链接分享
  • csdnceshi80 胖鸭 2013-04-08 18:34

    In my case, the view was not viewed in xib. in xib the View was size = none (4th tab right hand). I set size to Freeform and reload xCode. view was appealed and I set the proper link to View.

    点赞 评论 复制链接分享
  • csdnceshi59 ℙℕℤℝ 2015-02-10 18:11

    If you have tried everything and you still get this error, try re-creating the class file from scratch but remember to select the "Also create XIB file" check box. This will auto link up a few items that are not linked when creating these files separately. After this is created, you can likely cut and paste everything onto the new XIB and it should work fine.

    I am finding this issue specifically with creating files separately in Swift.

    点赞 评论 复制链接分享
  • csdnceshi50 三生石@ 2015-08-24 16:02

    for me it happened, when

    • I have a ViewController class ( .mm/h ) associated with the Nib file,
    • UIView from this ViewController has to be loaded on the another view as a subview,

    • we will call something like this

         CheckView *pCheckViewCtrl = [CheckView instance];
         pCheckView = [pCheckViewCtrl view];
         [[self view]addSubview:pCheckView];
         [pCheckViewCtrl performCheck];        


    +(CheckView *)instance{
        static CheckView *pCheckView = nil;
        static dispatch_once_t checkToken;
        dispatch_once(&checkToken, ^{
            pCheckView = [[CheckView alloc]initWithNibName:@"CheckView" bundle:nil];
            if ( pCheckView){
                [pCheckView initLocal];
                **[pCheckView loadView];**
        return pCheckView;

    Here loadView was missing,,, adding this line resolved my problem.

    点赞 评论 复制链接分享
  • csdnceshi74 7*4 2016-09-19 06:13

    I had the same problem, I figured out and it is because of i had ticked "Static cells" in the properties of Table View under Content option. Worked when it changed to "Dynamic Prototypes". Screenshot is below. enter image description here

    点赞 评论 复制链接分享
  • csdnceshi64 游.程 2018-05-16 09:34

    I had a similar problem with Xcode 9.3, and setting "Module" under the "File Owner's" attribute inspector to the project module fixed this for me.

    点赞 评论 复制链接分享
  • weixin_41568110 七度&光 2018-07-26 12:27

    The answer to problem for me was to make sure xib file name and swift file name should not be same. As when creating object of class it was giving priority to xib file and in that case XIB loading was failing to find View outlet.

    Example : I was having DataFragement.xib and DataFragment.swift

    and I was trying to create object like

    let fragment = DataFragment()

    to to solve this issue I renamed my xib file to data_fragment.xib and voila everything worked charm.

    点赞 评论 复制链接分享