ios “已加载笔尖但未设置视图插座”异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17321027/
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
"loaded nib but the view outlet was not set" exception
提问by erdemgc
I am trying to use UINavigationController
. I have two views which are being created programmatically. When a UIButton
is pressed on the first view, the second viewshould come to foreground.
我正在尝试使用UINavigationController
. 我有两个以编程方式创建的视图。当 aUIButton
在第一个视图上按下时,第二个视图应该出现在前台。
But here application crash with exception:
但这里应用程序崩溃异常:
loaded nib but the view outlet was not set
已加载笔尖但未设置视图插座
What can be cause of this and how to resolve it.
这可能是什么原因以及如何解决它。
回答by Nirav Gadhiya
follo following steps
遵循以下步骤
1) open your xib file then right click on files owner and drag to your first view
1) 打开您的 xib 文件,然后右键单击文件所有者并拖动到您的第一个视图
2) then bind that view with outlet of "view"
2)然后将该视图与“视图”的出口绑定
hope you will get it...
希望你会得到它...
回答by rptwsthi
Do This(You have no view in xib so add one and then do this):
执行此操作(您在 xib 中没有视图,因此添加一个然后执行此操作):
回答by sagarcool89
- 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并重新运行
Thanks,
谢谢,
回答by Gary Z
If you are not seeing the "view" outlet to select from on the "Connections inspector" (rightmost) tab, I found that I had to go back to a generic view controller (e.g., UICollectionViewController) for the File's Owner Custom Class instead of my subclass that I had entered previously. After closing and reopening Xcode, the view outlet appeared again so I connected it as described in sagarcool89's answer. I then set my File's Owner Custom Class back to my subclass and have finally moved past this error.
如果您没有在“连接检查器”(最右侧)选项卡上看到可供选择的“视图”出口,我发现我必须返回到 File's Owner Custom Class 的通用视图控制器(例如 UICollectionViewController)而不是我之前输入的子类。关闭并重新打开 Xcode 后,视图插座再次出现,所以我按照 sagarcool89 的回答中的描述连接了它。然后我将我的文件所有者自定义类设置回我的子类,并最终克服了这个错误。
回答by Travis M.
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.
如果您已经尝试了所有方法但仍然出现此错误,请尝试从头开始重新创建类文件,但请记住选中“同时创建 XIB 文件”复选框。这将自动链接一些单独创建这些文件时未链接的项目。创建后,您可以将所有内容剪切并粘贴到新的 XIB 上,它应该可以正常工作。
回答by Thomas E
Select File's owner
of your .xib, open the Identity Inspector
, make sure Custom Class
is set to the same name as your controller's class name. If you create IB file and Controller separately(in separate steps), you might forget to check this.
选择File's owner
您的 .xib,打开Identity Inspector
,确保Custom Class
设置为与您的控制器类名相同的名称。如果您分别创建 IB 文件和控制器(在不同的步骤中),您可能会忘记检查这一点。