ios 已加载笔尖但未设置“查看”插座

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4763519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:37:37  来源:igfitidea点击:

Loaded nib but the 'view' outlet was not set

ioscocoa-touchinterface-builderxib

提问by John

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

我在我的项目中添加了一个新的 nib 文件,并尝试加载它。

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

但是,当我单击应该带我进入我创建的视图的工具栏图标时,我收到一条NSInternalInconsistencyException消息:

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

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“...”笔尖,但未设置视图出口。

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?

所以我打开了我的 nib 文件,我看到没有设置引用插座的视图。但是,我尝试单击并将“新引用出口”的圆圈拖动到文件所有者,但它不会让我......我需要做什么才能显示我的视图?

采纳答案by John

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

未设置查看标识 - 类标识。将其设置为适当的类后,问题就解决了。

回答by Josh Justice

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
  • 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
  • 打开导致问题的 XIB 文件
  • 单击左侧栏上的文件所有者图标(顶部一个,看起来像一个黄色的框)
  • 如果您没有看到右侧边栏,请单击工具栏中“查看”上方的第三个图标。这将显示右侧边栏
  • 在右侧边栏中,单击第三个选项卡 - 看起来有点像报纸的选项卡
  • 在顶部的“自定义类”下,确保 Class 是应与此视图对应的 ViewController 的名称。如果没有,请输入
  • 在右侧边栏中,单击最后一个选项卡 - 看起来像一个带有箭头的圆圈的选项卡
  • 您应该会看到下面带有“view”的“outlets”。将旁边的圆圈拖到左侧栏上的“视图”图标(底部一个,看起来像一个带有粗灰色轮廓的白色方块
  • 保存xib并重新运行

回答by Javier Calatrava Llavería

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

这是 Josh Justice 的提议,但以图形方式(图片是我的):

  1. Select File owner
  2. On right hand side panel select custom class.
  3. Enter the custom class name
  1. 选择文件所有者
  2. 在右侧面板上选择自定义类。
  3. 输入自定义类名

enter image description here

enter image description here

  1. On right hand side panel select oultets
  2. Drag view outlet to view component
  1. 在右侧面板上选择 oultets
  2. 拖动视图出口查看组件

enter image description here

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];

回答by Rohit Mandiwal

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.

我通常可以通过重新建立文件所有者和视图之间的连接来修复它。按住 Control 键从文件所有者拖动到您的视图(在 IB 中),然后从弹出菜单中选择视图。

回答by Shehbaz Khan

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

你确定你有一个 UIView (或子类)分配给 yourViewController 的“view”属性吗?

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!

在 yourViewController 的 xib 的左窗格中右键单击“文件所有者”,并验证“视图”插座已设置。如果没有,请将其设置为视图!

this will definetly fix the Issue

这将明确解决问题

回答by vishal dharankar

For me all the things stated here https://stackoverflow.com/a/6395750/939501were 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.

对我来说,这里的所有内容https://stackoverflow.com/a/6395750/939501都是正确的,但仍然抛出错误,原因是我创建了一个名为 ABCView 的 View 类,然后将其删除,我添加了一个视图控制器作为ABCViewController 所以不知何故它指的是新视图控制器中的旧 ABCView,我不得不删除 ABCViewController 并添加一个不同名称的新控制器来解决我的问题。

Thanks

谢谢

回答by Nathan

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

我在 XCode 4.6.3 上遇到了同样的问题。我已经开始使用几个命名的文件MySettingsView.h.m但删除了它们以支持MySettingsViewController.h,但是尽管尝试了这里提到的大多数提示,它仍然不断出错,

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.'

2013-07-05 11:48:17.205 MyApp[39024:c07] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“MySettingsView”nib 但视图插座没有设置。

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.

它显然仍然“困惑”,试图加载 MySettingsView.xib 而不是 MySettingsView Controller.xib 。也许它的“做我的意思”逻辑太花哨了。

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

所以我通过在 MySettingsViewController.m 中硬编码 NIB/XIB 名称来解决这个问题:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:@"MySettingsViewController" bundle:nibBundleOrNil];
}

回答by manapate

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.

对于使用 xib 方法创建 UIView 并遇到此问题的任何人,您会注意到在连接检查器菜单下没有“视图”出口。但是,如果您将 File's Owners 自定义类设置为 UIViewController,然后您将看到“视图”插座,您只需通过 CMND 将插座连接到 CustomView。

回答by Matt

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!

我的问题是由于在没有设置视图的类文件夹中有重复的笔尖引起的。xcode 似乎为构建选择了一个笔尖,然后在我下次构建项目时选择了另一个笔尖。刚刚删了另一个。看起来挺好的。哦!

回答by Kamil.S

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.

刚刚花了一个多小时试图找出为什么我的视图属性没有在我的视图控制器中设置时从笔尖启动。请记住在视图控制器的 initWithNibName 中调用“[super initWithNibName...]”。