xcode 加载了 nib 文件但未设置视图插座

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11665113/
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-09-15 01:01:51  来源:igfitidea点击:

Loaded the nib file but the view outlet was not set

iphoneiosxcode

提问by JaNa Saadeddin

I deleted the universityPicker.xib accidentally and then made a new one with the same name but no connection could be done. The file crashes and gives this message

我不小心删除了 universityPicker.xib,然后创建了一个同名的新文件,但无法建立连接。文件崩溃并给出此消息

reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "universityPicker" nib but the view outlet was not set."

How I can fix it?

我该如何解决?

回答by Ali Abbas

  • Open the universityPicker.XIB file
    • Click on file's owner icon on the left bar
    • Click on the third tab in the right-hand sidebar
    • 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
    • You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar
    • Save the xib and re-run
  • 打开 universityPicker.XIB 文件
    • 单击左侧栏中的文件所有者图标
    • 单击右侧边栏中的第三个选项卡
    • 在顶部的“自定义类”下,确保 Class 是应与此视图对应的 ViewController 的名称。如果没有,请输入
    • 在右侧边栏中,单击最后一个选项卡
    • 您应该会看到下面带有“view”的“outlets”。将旁边的圆圈拖到左侧栏上的“查看”图标上
    • 保存xib并重新运行

回答by Templar

In the Interface Builder you should connect the View to the File's Owner.

在界面生成器中,您应该将视图连接到文件的所有者。