View outlet not available to File's Owner
I was getting the following message upon creating a new view controller. Everything was compiling a-okay in Xcode without errors, but the app was immediately quitting upon loading the new view from a RootViewController.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[U开发者_StackOverflow中文版IViewController _loadViewFromNibNamed:bundle:] loaded the "HomeView" nib but the view outlet was not set.'
To resolve this, I tried connecting the File's Owner to the view, but the view outlet wasn't even available to the File's owner.
Moved from question section, per @Tim Post's suggestion.
Discovery:
I finally realized that when I added this View XIB, the File's Owner had been set to NSObject instead of HomeViewController (my newly-created view controller). Once I set the class identity in the indentity inspector, the view outlet was then ready to be connected to the view.
The app now loads and the new view loads perfectly. Just sharing for the benefit of the SO community.
Conclusion:
When creating a new View XIB, make sure to set the class identity to the desired view controller in the indentity inspector (Cmd+4). It may be set to NSObject by default.
The view outlet should then be available.
精彩评论